【发布时间】:2016-02-21 15:30:54
【问题描述】:
我正在尝试配置 select2 插件。目前它工作正常,但是当我尝试禁用区分大小写时,我无法弄清楚。
下面是代码。
<script type="text/javascript">
var lastResults = [];
$("#tags").select2({
multiple: true,
tags: true,
placeholder: "Please enter keywords",
tokenSeparators: [',', ' '],//[","],
initSelection : function (element, callback) {
var data = [];
$(element.val().split(",")).each(function () {
data.push({id: this, text: this});
});
callback(data);
},
ajax: {
multiple: true,
url: "fetch_keywords.php",
dataType: 'json',
data: function(term,page) {
return {
term: term
};
},
results: function(data,page) {
lastResults = data;
return {results: data};
},
},
maximumSelectionSize: 3,
minimumInputLength: 3,
maximumInputLength: 30,
createSearchChoice: function(term) {
var text = term + (lastResults.some(function(r) {
return r.text == term
}) ? "" : " (new)");
return {
id: term,
text: text
};
},
});
我已经检查了这个问题select2: Disable case-sensitive matches,但我不确定如何在我的代码中使用它。
如果用户输入 test 那么它将从数据库中返回匹配但如果用户输入 Test 然后它会创建一个新标签。
谢谢
【问题讨论】:
-
我有另一个关于禁用区分大小写的答案,请检查here。
标签: jquery jquery-select2 jquery-select2-4