我正在使用Select2的最新版本4.0.12。
我的下拉列表如下:
<select id="langselect">
<option data-lang="Английский">English</option>
<option data-lang="Русский">Russian</option>
</select>
我使用matcher
选项按首字母搜索:
function matchStart(term, text) {
if (text.toUpperCase().indexOf(term.toUpperCase()) == 0) {
return true;
}
return false;
}
$.fn.select2.amd.require(['select2/compat/matcher'], function(oldMatcher) {
$("#langselect").select2({
matcher: oldMatcher(matchStart),
});
});
我还需要更改matchStart()
函数以也开始在data-*
属性中进行搜索。我正在尝试这样的事情:
if ($(data.element).data('lang').toUpperCase().indexOf(term.toUpperCase()) == 0) {
return true;
}
但是我遇到了Cannot read property 'indexOf' of undefined
错误。
请帮助解决此错误。