限制的结果jQuery用户界面自动完成

问题描述:

我使用jQuery UI自动完成。

I am using jQuery UI Autocomplete.

 $("#task").autocomplete({
     max:10,
     minLength:3,
     source: myarray
 });          

最大参数不工作,我仍然得到超过10个结果。我缺少的东西吗?

The max parameter doesn't work and I still get more than 10 results. Am I missing something?

下面是 href=\"http://jqueryui.com/demos/autocomplete/\">适当的文件 jQueryUI的小部件。没有限制的最大成果内置的参数,但你可以很容易地完成它:

Here is the proper documentation for the jQueryUI widget. There isn't a built-in parameter for limiting max results, but you can accomplish it easily:

$("#auto").autocomplete({
    source: function(request, response) {
        var results = $.ui.autocomplete.filter(myarray, request.term);

        response(results.slice(0, 10));
    }
});

您可以提供一个功能到参数,然后调用slice$c$c>对滤波阵列

You can supply a function to the source parameter and then call slice on the filtered array.

这里有一个工作的例子: http://jsfiddle.net/andrewwhitaker/vqwBP/