【发布时间】:2019-10-11 19:52:29
【问题描述】:
我正在关注给定 in this thread 的 JSFiddle 作为从简单的对象数组加载 jQuery UI AutoComplete 的解决方案:
这里的过滤被破坏了。有 2 个数据行带有 First_Name 字符串,“Will”和“Willem”,但如果您键入其他内容,例如“WA”你仍然可以得到 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;
}
【问题讨论】:
-
您需要将地图数据传回过滤。使用
$.ui.autocomplete.filter()示例:jqueryui.com/autocomplete/#multiple
标签: jquery jquery-ui jquery-ui-autocomplete