我有一个下拉列表,在其中键入2个或更多符号后,它将开始在base nad中搜索返回值。如果没有搜索到,我希望用户能够将该标签添加为新标签。到目前为止,这是我的代码
$("#tags,#TagId").select2(
{
allowClear: true,
ajax: {
url: "/Entry/ReadSelect2DataMulti",
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term,
page: params.page || 1
};
},
processResults: function (data, params) {
params.page = params.page || 1;
return {
results: data
};
},
cache: true,
error: function (xhr, textStarus, error) {
}
},
minimumInputLength: 2,
placeholder: "აირჩიეთ პოზიცია",
templateResult: function (state) {
var result = '<div class="pos-template">' + '<span title=""><b>' + state.text + '</b></span>';
if (state.content != null && state.content != '') {
var tags = state.content.split(",");
for (i = 0; i < tags.length; i++) {
result = result + '<span class="pos-tag">' + tags[i] + '</span>';
}
} else {
}
result = result + '</div></div>';
return $(result);
},
createSearchChoice: function (term, data) {
if ($(data).filter(function () {
return this.text.localeCompare(term) === 0;
}).length === 0) {
return { id: term, text: term };
}
},
language: {
noResults: function () {
return "პოზიცია ვერ მოიძებნა";
},
inputTooShort: function () {
return "შეავსეთ მინიმიმ 2 სიმბოლო";
},
loadingMore: function () {
return 'იტვირთება...';
},
searching: function () {
return 'იფილტრება...';
}
}
}
);
但是此createSearch不会执行任何操作。
<div class="form-group">
<select multiple="multiple" class="form-control" id="tags" style="width: 400px;"></select>
</div>
这是我的div部分。有什么建议么 ?