$('.select2.base-product').select2({
minimumInputLength: 1,
ajax: {
url: "@Url.Action("GetBaseProducts", "Promotion")",
dataType: 'json',
quietMillis: 250,
data: function(term, page) {
return {
searchTerm: term, // search term,
pageSize: 15,
pageNum: page
};
},
results: function(data, page) { // parse the results into the format expected by Select2.
return { results: data.items };
},
cache: true
},
initSelection: function(element, callback) {
var id = $(element).val();
var formatId = $(element).attr('data-formatid');
if(id.length > 0) {
$.ajax('@Url.Action("GetBaseCategoryById", "Promotion")', {
dataType: 'json',
data: {
id: id, formatId: formatId
}
}).done(function (data) {
console.log(data.items);
callback(data.items);
});
}
},
escapeMarkup: function(markup) { return markup; } // let our custom formatter work
});
您好,初始化select2输入时遇到了很大问题。我的动作GetBaseCategoryById返回一个对象,例如
[Object]
0: Object
id: "33:2613"
text: "Naklejki: Okrągła"
__proto__: Object
length: 1
__proto__: Array[0]
对我来说这样的结果对于select2来说是正确的,但是输入是空的。有谁可以帮我这个?