对jQuery Autocomplete中的值进行排序 [英] Sort the values in the jQuery Autocomplete
问题描述
我有一个像这样的数组
["JOAQUIN", "BERNARDINO", "MODOC","ALASKA","MADERA", "ANDERSON"]
我在 jQuery UI Autocomplete
中填充它们的位置.但是,排序顺序似乎很奇怪.
例如:(但是我有更多的记录数)当我键入"a" 时,它将返回
where I'm populating them in a jQuery UI Autocomplete
. However the order of sorting seems to be weird.
For example:(But I have more no.of records) When I type "a" it returns
JOAQUIN
BERNARDINO
ALASKA
MADERA
ANDERSON
我正在尝试获取(以开头)
What I'm trying is to get (starting with)
ALASKA
ANDERSON
以
JSFiddle 为例
有可能吗?有人可以指出我正确的方向.
Is it possible? Can someone point me in a right direction.
更新:
推荐答案
var myarray= ["JOAQUIN", "BERNARDINO", "MODOC","ALASKA","MADERA", "ANDERSON"]
myarray.sort();
我们将两个参数传递给源,第一个是request
,第二个是response
,
we are passing two arguments into source one is request
and second is response
,
-
request
代表我们正在创建的请求对象,在我们的情况下是 我们在文本框中输入的字母.
request
is stands for request object we are making, in our case it is the letter we are typing into textbox.
response
是具有以下功能的函数
将返回给我们自动完成选择选项.
response
is function which
will return us auto complete selection options.
现在在$.map
内部,我们正在检查带有已命名为json的数组的键入的单词.
now inside $.map
we are checking typed words with array we have named json.
json.toUpperCase().indexOf(request.term.toUpperCase())
此行将键入的单词和数组转换为相同的大小写并返回.
json.toUpperCase().indexOf(request.term.toUpperCase())
this line convert typed word and array to same case and return it.
和匹配项将是最终结果,其中包含您所要求的项目列表.
and matches would be the final result which has list of item that you have asked.
和response(matches);
会将其发送到自动完成功能.
and response(matches);
will send it to autocomplete.
这篇关于对jQuery Autocomplete中的值进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!