jquery ui autocomplete without filter

我是研究僧i 提交于 2019-12-23 13:16:24

问题


I need to show user all autocomplete choices, no matter what text he already wrote in the field? Maybe i need some other plugin?

$('#addressSearch').autocomplete("search", "");

That doesn't work.


回答1:


There are two scenarios:

  1. You're using a local data source. This is easy to accomplish in that case:

    var src = ['JavaScript', 'C++', 'C#', 'Java', 'COBOL'];
    $("#auto").autocomplete({
        source: function (request, response) {
            response(src);
        }
    });
    
  2. You're using a remote data source.

    $("#auto").autocomplete({
        source: function (request, response) {
            // Make AJAX call, but don't filter the results on the server.
            $.get("/foo", function (results) {
                response(results);
            });
        }
    });
    

Either way you need to pass a function to the source argument and avoid filtering the results.

Here's an example with a local data source: http://jsfiddle.net/andrewwhitaker/e9t5Y/




回答2:


You can set the minLength option to 0, then it should work.



来源:https://stackoverflow.com/questions/7526354/jquery-ui-autocomplete-without-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!