Я слежу за JSFiddle, данным в этой теме в качестве решения для загрузки автозаполнения пользовательского интерфейса jQuery из простого массива объектов:
http://jsfiddle.net/khsbme4k/
Фильтрация здесь нарушена. Есть 2 строки данных со строкой First_Name, «Will» и «Willem», но если вы наберете что-нибудь еще, например, «ВА» вы все равно получаете полный выбор из 2 предметов, где их не должно быть.
var data = [
{
"id": 1,
"first_name": "Will",
"last_name": "Smith",
"created_at": "2015-01-27T13:09:20.243Z",
"updated_at": "2015-01-27T13:09:20.243Z"
},
{
"id": 2,
"first_name": "Willem",
"last_name": "Dafoe",
"created_at": "2015-01-27T13:17:23.479Z",
"updated_at": "2015-01-27T13:17:23.479Z"
}
];
$('#search').autocomplete({
// This shows the min length of charcters that must be typed before the autocomplete looks for a match.
minLength: 2,
source: function (request, response) {
response($.map(data, function (value, key) {
return {
label: value.first_name,
value: value.id
}
}));
},
focus: function(event, ui) {
$('#search').val(ui.item.first_name);
return false;
},
// Once a value in the drop down list is selected, do the following:
select: function(event, ui) {
// place the person.given_name value into the textfield called 'select_origin'...
$('#search').val(ui.item.first_name);
// and place the person.id into the hidden textfield called 'link_origin_id'.
$('#link_origin_id').val(ui.item.id);
return false;
}