1
オートコンプリートjquery jsonを使用していますが、結果が表示されません。 私は次のコードを使用しています。Jqueryオートコンプリートでデータが表示されない
$(function() {
$("#course").autocomplete({
source: function(request, response) {
$.ajax({
url: "ajax.php",
dataType: "json",
data: {
style: "full",
maxRows: 20,
name_startsWith: request.term
},
success: function(data) {
response($.map(data.geonames, function(item) {
return {
Id: item.Id + (item.FirstName ? ", " + item.LastName : "") + ", " + item.Email,
value: item.Id
}
}));
}
});
},
minLength: 2,
select: function(event, ui) {
log(ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
},
open: function() {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function() {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
});
</script>
この形式のAjaxファイルになります。メニュー項目のデフォルトのレンダリング方法があるので
{[label: 'text', value: 'val']...}
:
_renderItem: function(ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append($("<a></a>").text(item.label))
.appendTo(ul);
}
あなたがしたい場合は
[{"Email":"[email protected]","FirstName":"Sobha","Id":12333,"LastName":"Marati"}]