selec2搜索-如果特定条件不匹配,则返回未找到结果消息 [英] selec2 search - Return no results found message if a specific criteria didnt match
本文介绍了selec2搜索-如果特定条件不匹配,则返回未找到结果消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用select2 4.0.3进行搜索.根据我的理解,其默认功能与下拉菜单项的开头不匹配.所以我实现了下面给出的代码
I am using select2 4.0.3 for search drop down. As per my understanding its default functionality is not to match with the start of entries the drop down have. So I have implemented the below given code
function matchStart(params, data) {
params.term = params.term || '';
if (data.text.toUpperCase().indexOf(params.term.toUpperCase()) == 0) {
return data;
}
return false;
}
$("select").select2({
placeholder : "Input country name or select region",
matcher : function (params, data) {
return matchStart(params, data);
},
});
我的问题是,即使没有找到匹配的结果,下拉列表也不会显示找不到结果"消息.谁能帮我这个忙.
My problem is, the dropdown is not showing "No results found" message even if there is no matching results found. Can anyone help me on this.
谢谢.
推荐答案
尝试将matchStart
的返回值从false
更改为null
.
Try changing the return value of matchStart
from false
to null
.
此外,您可以删除matcher
参数周围的额外功能.结果:
Also you can remove the extra function around the matcher
argument. The result:
function matchStart(params, data) {
params.term = params.term || '';
if (data.text.toUpperCase().indexOf(params.term.toUpperCase()) == 0) {
return data;
}
return null;
}
$("select").select2({
placeholder: "Input country name or select region",
matcher: matchStart
});
这篇关于selec2搜索-如果特定条件不匹配,则返回未找到结果消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文