Limit the result in jQuery Autocomplete

前端 未结 5 1574
情书的邮戳
情书的邮戳 2021-01-04 18:45

How can you set a limit on the result from the jQuery autocomplete?

This is my code:

        $.ajax({
            url: \"/cache/search/SearchModels.x         


        
5条回答
  •  孤独总比滥情好
    2021-01-04 19:32

    The quickest way to limit results is doing it during the "open" event. We can delete part of the content dynamically created by jquery ui, reducing the children element array.

    This solution solved the same issue for me:

    var maxResults = 10;
    $input.autocomplete({
        source: somefile.json,
        open: function(event,ui){
              $(this).data("uiAutocomplete").menu.element.children().slice(maxResults).remove();
             }
    })
    

提交回复
热议问题