0
我在點擊提交或頁面回發時沒有顯示select2值時出現問題。我使用ajax helper從數據庫加載數據。Select2多選的值在回發後不被保留
這裏是我的選擇2碼:
$('#<%=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);
}
}
});