我想用select2插件使用自定義匹配器,但我得到一個錯誤「text.toUpperCase()」未定義。我已經遵循了這些例子,但無法實現。任何幫助,將不勝感激。我的代碼如下:select2自定義匹配器toUpperCase未定義
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.min.js"></script>
<script type="text/javascript">
$('.selectpicker').select2({
placeholder: 'Select an option',
matcher: function(term, text) {
var has = true;
var words = term.toUpperCase().split(" ");
for (var i =0; i < words.length; i++){
var word = words[i];
has = has && (text.toUpperCase().indexOf(word) >= 0);
}
return has;
}
});
</script>
你使用的是什麼版本:v4或v3? – Shrike