开发者

jQuery autocomplete modification Gmail like matching

$("#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 开发者_如何学Gotype '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.


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

type 'bl' for example


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜