问题描述
我将 Select2 用于选择框,并且Select2没有搜索区分大小写的数据。例如,我在列表中有 LHE ,但是当我搜索 lhe 时,它什么也没有显示,这是我正在使用的代码,将不胜感激。相信我,我已经阅读了许多解决方案,也尝试过这些解决方案,但是都没有用。这是代码。
<script>
function matchCustom(params,data) {
// If there are no search terms,return all of the data
if ($.trim(params.term) === '') {
return false;
}
// Do not display the item if there is no 'text' property
if (typeof data.text === 'undefined') {
return null;
}
// `params.term` should be the term that is used for searching
// `data.text` is the text that is displayed for the data object
if (data.text.indexOf(params.term) > -1) {
var modifiedData = $.extend({},data,true);
modifiedData.text;
// You can return modified objects from here
// This includes matching the `children` how you want in nested data sets
return modifiedData;
}
// Return `null` if the term should not be displayed
return null;
}
$(document).ready(function () {
$(".destination").select2({
matcher: matchCustom,});
$(".departure").select2({
matcher: matchCustom,});
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)