我正在处理select2 v4,我想预加载一些值,并且还需要ajax,我试图工作,但是它对我不起作用,有人可以帮我做错什么吗?这是我的代码
var selected = [];
var initials = [];
initials.push({id: 'Test1', name: 'Test1'});
$("#tagSelectPost").select2({
minimumInputLength: 0,
placeholder: "Select tag",
data: initials,
ajax: {
url: '<?php echo base_url(); ?>post/gettag',
dataType: 'json',
type: "GET",
quietMillis: 50,
multiple: false,
data: function (term) {
return {
term : term,
id : "<?php echo $t['user_profile_details']->id; ?>",
postid : ' <?php echo $t['post_details']['id']; ?>'
};
},
results: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.text,
id: item.id
}
})
};
}
}
});