限制的结果jQuery用户界面自动完成 [英] Limit results in jQuery UI Autocomplete

查看:178
本文介绍了限制的结果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));
    }
});

您可以提供一个功能到参数,然后调用<一个href=\"https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/slice\"><$c$c>slice对滤波阵列

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

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

这篇关于限制的结果jQuery用户界面自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆