Limit the result in jQuery Autocomplete

前端 未结 5 1576
情书的邮戳
情书的邮戳 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:28

    This is what I did based on some reading of the autocomplete API docs

    $input.autocomplete({
      source: function( request, response ) {
        $.getJSON('search.php', request, function( data, status, xhr ) {
          // return a max of 10 results.
          response( data.slice(0, 9) );
        });
      }
    })
    

    Following this pattern saves having to do any funky stuff in the render layer.

提交回复
热议问题