简体   繁体   中英

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. When I type a character into the box it suggests all the 100-150 options at once.

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?

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 .

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.

This would result in less results than for example 1. You could also use slice .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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