简体   繁体   English

通过在 Select2 插件中使用匹配器功能,不会出现未找到结果的消息

[英]By using a matcher function in Select2 plugin, no results found message is not appearing

In normal the the no results found message shows when unrecognised name enters, but by adding the below code to filter results to show only the first letter matches there is no message shown.在正常情况下,当输入无法识别的名称时会显示 no results found 消息,但通过添加以下代码来过滤结果以仅显示第一个字母匹配,则不会显示任何消息。

 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",

    noResults: function () {
        return"No results found"
    },
    matcher: function (params, data) {
        return matchStart(params, data);
    },
});

Know this is an old one but I managed to find an answer here: selec2 search - Return no results found message if a specific criteria didnt match知道这是一个旧的,但我设法在这里找到答案: selec2 搜索 - 如果特定条件不匹配,则返回未找到结果消息

So credit to user ikkuh for the answer.因此,感谢用户 ikkuh 的回答。 My issue was with returning false in the matcher function, try returning null instead - worked for me!我的问题是在匹配器函数中返回 false,尝试返回 null - 对我有用!

You need replace "return false;"您需要替换“返回假;” to "return null;" “返回空值;” in function matchStart在函数 matchStart 中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM