jQuery的,自动完成匹配的过滤器按首字母 [英] jQuery-autocomplete filter match by first letter

查看:501
本文介绍了jQuery的,自动完成匹配的过滤器按首字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的插件创建自动完成功能:

I am using below plugin to create autocomplete feature:

https://github.com/devbridge/jQuery-Autocomplete

下面是他们的现场演示:

below is their live demo:

http://www.devbridge.com/sourcery/components/jquery-autocomplete/#jquery-autocomplete

现在的问题是,我想过滤的结果,并只显示字母比赛开始第一个字母。

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

例如,如果我输入到'一',只有国家开始'A'应该会出现。

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

我查了一下这个插件的图书馆,我看到有一个 lookupFilter 的功能有,但不知道如何使用它。

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?

我想使用这个插件,而不是jQuery UI的,因为它是重量轻。

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

推荐答案

我检查了他们的 lookupFilter 在他们的图书馆及以下有code

I checked their lookupFilter in their library and below is there code

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

在这里,他们bascially返回值,如果美元的结果p $ psent。

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

1 表示字母A不可用,所以他们在任何事件返回值。

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

所以才调为

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

正好在第0指数。

这将返回A作为第一次出现。

This will return the results with 'a' as first occurance.

这篇关于jQuery的,自动完成匹配的过滤器按首字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆