jQuery UI的自动完成使用startsWith [英] jQuery UI Autocomplete use startsWith
本文介绍了jQuery UI的自动完成使用startsWith的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jQuery UI的自动完成与本地数据源(来源:myArray的
)。我想自动完成建议只的的结果开始的字符串输入的,而不是默认的不区分大小写包含的搜索。对此有一个简单的解决方案或我提供我的自定义搜索/来源回调?
I'm using the jQuery UI Autocomplete with a local datasource (source: myArray
). I want the autocomplete to propose only the results that start with the string entered instead of the default case-insensitive contains search. Is there a simple solution for this or do I have to provide my custom search/source callback?
推荐答案
目前我已经这样做了,不知道是否有更好的解决方案:
Currently I've done it this way, not sure if there is a better solution:
source: function(request, response) {
var filteredArray = $.map(orignalArray, function(item) {
if( item.value.startsWith(request.term)){
return item;
}
else{
return null;
}
});
response(filteredArray);
},
这个方法也使人们有可能对项目的数量加以限制(例如10个项目)中显示。
This approach also made it possible to impose a limit (e.g. 10 items) on the amount of items to be shown.
这篇关于jQuery UI的自动完成使用startsWith的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文