【发布时间】:2014-01-22 16:34:40
【问题描述】:
我遇到了一个问题,即单击提交或页面回发时未显示 select2 值。我正在使用 ajax 助手从数据库加载数据。
这是我的 select2 代码:
$('#<%=fstName.ClientID%>').select2({
placeholder: 'Enter Reviewer',
minimumInputLength: 0,
multiple: true,
autoClear:false,
ajax: {
type: 'POST',
url: 'BulkPickers/GetRev',
dataType: 'json',
data:
function (term, page) {
return {
appinstid: appInstId,
searchTerm: term,
selection: $('#<%=fstName.ClientID%>').val()
};
},
results: function (data, page) {
var myResults = [];
$.each(data, function (index, item) {
myResults.push({
id: item.id,
text: item.text
});
});
return {
results: myResults
};
},
initSelection:
function (element, callback) {
var data = [];
$(element.val().split(",")).each(function () {
data.push({ id: this, text: this });
});
callback(data);
}
}
});
【问题讨论】: