javascript - jQuery-autocomplete filter match by first letter - Stack Overflow

I am using below plugin to create autoplete feature:below is their live demo:now the problem is, I'

I am using below plugin to create autoplete feature:

below is their live demo:

now the problem is, I'd like to filter the result and only show letter match start with first letter.

for example, if I typed into 'a', only countries start with 'a' should appear.

I checked this plugin's library, I saw there is a lookupFilter function there, but don't know how to use it.

would anyone who had used this library before kindly give some pointers?

I'd like to use this plugin instead of jQuery UI, as it is light weighted.

I am using below plugin to create autoplete feature:

https://github./devbridge/jQuery-Autoplete

below is their live demo:

http://www.devbridge./sourcery/ponents/jquery-autoplete/#jquery-autoplete

now the problem is, I'd like to filter the result and only show letter match start with first letter.

for example, if I typed into 'a', only countries start with 'a' should appear.

I checked this plugin's library, I saw there is a lookupFilter function there, but don't know how to use it.

would anyone who had used this library before kindly give some pointers?

I'd like to use this plugin instead of jQuery UI, as it is light weighted.

Share Improve this question edited Apr 23, 2014 at 9:13 JavaScripter asked Apr 23, 2014 at 9:07 JavaScripterJavaScripter 4,85210 gold badges39 silver badges45 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 5

I checked lookupFilter in their library and below is the code:

lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
    return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
},

Here they are returning the value bascially if it is present in the results.

-1 means the letter a is not found, so they're returning the value at any occurrence.

So just tune it as:

lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
    return suggestion.value.toLowerCase().indexOf(queryLowerCase) === 0;
},

Exactly at 0th index.

This will return the results with a as first occurance.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745398500a4625991.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信