Вы можете добавить необходимую информацию в data
атрибутах.
{% for item in people %}
<a id="foo" class="foo" data-people-id="{{item[1]}}" data-people-name="{{item[1]}}">{{item[1]}}</a>
{% endfor %}
Тогда просто получите нужные данные при нажатии на якорь.
function anchorClickHandler(evt) {
var anchor = $(this)[0]; // get the anchor DOM element, unwrapped from jQuery
var peopleId = anchor.dataset.peopleId; // get the peopleId from the data attribute
var peopleName = anchor.dataset.peopleName; // you can do the same with the name, if you want
$.ajax({
url: "/~s6/cgi-bin/people.py",
async: true,
type: "post",
datatype: "json",
data: {
'peopleid': peopleId, // pass in the peopleId from the specific anchor that was clicked.
},
success: function(result) {
console.log(result)
// console.log(result.peopleinfo.surname)
// console.log(result.peopleinfo.othernames)
console.log(result.familyinfos)
html = '<table class="table table-striped table-bordered table-condensed">' +
'<tr>' +
'<th>Old Name</th>' +
'<td>' + result.peopleinfo.surname + '</td>' +
'</tr>' +
'</table>'
$('#infoTab').html(html)
$("#placenameModal").modal("show");
}
});
}
$(".foo").on('click', anchorClickHandler);
Также неплохо определить ваши обработчики вне фактического назначения.
Если бы вы определяли ваши обработчики в цикле, то вместо вашего обработчика связывалась бы копия вашего обработчика.
Хотя вы не заметите разницу на небольших страницах, она не масштабируется вообще и может повлиять на производительность на больших страницах.