当我在输入中写一些字母时,select2进入控制器,找到经过过滤的匹配项,并在视图中返回我需要的文本。当我选择文本并发布所有标签ID时,就不会显示文本。我要张贴文字,而不是任何建议吗? 我将所有输入发送到controller的tag []中。如果该值不存在,则以文本形式发布,但如果找到,则以id形式发布
HTML
<select multiple="multiple" class="form-control" id="tags" style="width: 400px;" value="tags" name="tags[]"></select>
<script>
$("#tags").select2(
{
allowClear: true,
tags: true,
tokenSeparators: [',', ' '],
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>';
}
}
result = result + '</div></div>';
return $(result);
},
id: function (object) {
return object.text;
},
language: {
noResults: function () {
},
inputTooShort: function () {
return "შეავსეთ მინიმიმ 2 სიმბოლო";
},
loadingMore: function () {
return 'იტვირთება...';
},
searching: function () {
return 'იფილტრება...';
}
},
}
);
//$('#tags').select2('val');