2

Example data:

var data = [{label:"Jonathan Montiel",value:"28465"},{label:"Jackson C. Gomes",value:"5145692"}];

Autocomplete code:

$("#tagName").autocomplete({        
            source: function(request, response) {
                response(data);
            },
            select: function( event, ui ) {
                $( "#tagName" ).val( ui.item.label); 
                return false;
            }
        });

When I type in input with id #tagName, autocomplete options show but do not reduce as I type, any letter input leaves same autocomplete result e.g. typing ja leaves both options showing.

Is there a glaring error?

4

2 回答 2

1
$("#tagName").autocomplete({        
            source: data //updated here
            },
            select: function( event, ui ) {
                $( "#tagName" ).val( ui.item.label); 
                return false;
            }
        });

对我来说很好,jquery 1.9.1UI 可以直接传入 json 数据。

jsfiddle

于 2013-05-26T19:42:47.817 回答
1

我对大型外部数据集也有类似的问题。我通过将数据加载到局部变量中并使用该变量作为自动完成函数中的源来解决它。

于 2013-06-20T23:20:02.737 回答