简体   繁体   English

如何限制jQuery自动完成程序中显示的选项数量?

[英]How do I limit the number of options displayed in jQuery's autocompleter?

I am using Jquery autocompleter with a list of about 200 items. 我正在使用约200个项目的列表的Jquery自动完成程序。 When I type a character into the box it suggests all the 100-150 options at once. 当我在框中输入字符时,会立即建议所有100-150个选项。

The list is so long it extends well beyond the page bottom border and also gives horrible performance. 该列表是如此之长,它远远超出了页面底部的边界,并且还提供了可怕的性能。

How can I limit the number of options displayed to a reasonable number like 5 or 6? 如何将显示的选项数量限制为合理的数量(例如5或6)?

The official documentation given here does not help. 此处给出的官方文档无济于事。

What is the way to limit the length of the list? 限制列表长度的方法是什么? Is there another autocompleter library that offers good performance? 是否有另一个提供良好性能的自动完成程序库?

Use: 采用:

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

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

This was found in Limit results in jQuery UI Autocomplete . 这是在jQuery UI Autocomplete中的Limit结果中发现的。

http://api.jqueryui.com/autocomplete/#option-minLength http://api.jqueryui.com/autocomplete/#option-minLength

If you use the minLength option, for example 3, then the user would have to type three characters before the filter starts. 如果使用minLength选项(例如3),则用户必须在过滤器启动之前键入三个字符。

This would result in less results than for example 1. You could also use slice . 这将导致比示例1更少的结果。您也可以使用slice

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM