How can I make jquery autocomplete search in all the words seperated by a whitespace

大兔子大兔子 提交于 2020-01-06 07:17:09

问题


Suppose in the source of jQuery autocomplete I have a word like SELINA RISEWA MIL.

But if I type SELINA MIL jQuery autocomplete doesn't return that option. How can I change that?


回答1:


You have to implement this in your search logic from where you are returning your JSON response containing the suggestions.




回答2:


You can use Regular Expressions-- say like this

        $('#elem').autocomplete({
            source: function(request, response) {
                var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term, ""));
                var data = $.grep( array, function(value) {
                    return matcher.test( value.label || value.value || value );
                });
                response(data);
            }
        });


来源:https://stackoverflow.com/questions/15428071/how-can-i-make-jquery-autocomplete-search-in-all-the-words-seperated-by-a-whites

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