jQuery autocomplete modification Gmail like matching

拥有回忆 提交于 2019-12-08 05:36:18

问题


$("#suggest3").autocomplete(someArray, {
    multiple: true,
    mustMatch: true,
    autoFill: true

});

"Jhon Smith" 
"Borris Baker" 
"Dove Elliot" 

Now in the above combination when i would type 'Jhon Smith' a value ( Jhon Smith ) will be available in the dropdown....But how to tweak so that even when i type 'Smith Jhon' still the value ( Jhon Smith ) is available for selection... :s

i.e. Like in Gmail no matter what is the sequence of the words included in the name of a person it shows that result as long as the 'Jhon' and 'Smith' is there... i.e. sequence doesn't matter.


回答1:


Here is an example of Gmail style matching: http://jsbin.com/utojoh/2

type 'bl' for example




回答2:


The Jquery Autocomplete plug-in you are using probably can't be tweaked easily to your requirements. However you can get some hints from this script:
Source for "Google Contacts Autocomplete" – Userscripts.org




回答3:


In my case, I pulled the result set from a database after I split the words and used a LIKE clause in the SQL.

EDIT: Just and FYI, I did a sort so that if they entered "Jhon Smith" it would put results in priority order:

Jhon Smith
Jhon Smithy
Jhon Friday
Carl Smith


来源:https://stackoverflow.com/questions/1678936/jquery-autocomplete-modification-gmail-like-matching

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