限制 jQuery UI 自动完成中的结果 [英] Limit results in jQuery UI Autocomplete

查看:33
本文介绍了限制 jQuery UI 自动完成中的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jQuery UI 自动完成功能.

I am using jQuery UI Autocomplete.

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

max 参数不起作用,我仍然得到 10 多个结果.我错过了什么吗?

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

推荐答案

这里是适当的文档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));
    }
});

您可以为 source 参数提供一个函数,然后调用 slice 在过滤后的数组上.

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

这是一个工作示例: http://jsfiddle.net/andrewwhitaker/vqwBP/

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

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