我有一个要搜索的名称列表,其中还包含一个 id 值,我想在选择时使用它来查找更多信息并使用它填充表单。生成的列表如下所示:
<script>
$(function() {
var allplayers = [
{ label: "Name of one", id:"1393" },
{ label: "Name of two", id:"325" },
{ label: "Name of one", id:"637" }
];
}
$( "#searchplayers" ).autocomplete({
source: allplayers
});
$( "#searchplayers" ).bind( "autocompleteselect", function(event, ui) {
alert(ui.item.id); //this is how to get item id
});
</script>
现在它只是将值添加到文本输入中,我如何在调用 select 函数时获取与其关联的 id。如何获取对象的 id?