为了填充我的下拉列表,我正在使用ajax调用函数并获取我想要的记录,然后我使用$.map将id和文本更改为我使用的列名。
一切正常,但现在我陷入了如何为下拉列表提供默认值的问题:
$(".js-firme-data-array").select2( {
ajax: {
// The number of milliseconds to wait for the user to stop typing before issuing the ajax request
delay: 400,
url: "<?php echo site_url('proiecte/get_firme') ?>",
dataType: "json",
cache: "true",
data: function (params) {
return {
q: params.term, // search term
page: params.page,
};
},
processResults: function (data) {
return {
results: $.map(data, function(obj) {
return { id: obj.id, text: obj.denumire };
})
};
},
},
});
如果其他人正在寻找这个,请找到解决方案:
initSelection : function (element, callback) {
var data = {id: "your id", text: "your text"};
callback(data);
},