在 initSelection
上使用 select2 插件时出现以下错误。
错误:未捕获错误:没有 select2/compat/initSelection
是我收到的错误。
希望有人帮助我解决 inistselection
问题。
JS:
$(".doctor_id_pat").select2({
placeholder: "Search Users",
minimumInputLength: 2,
ajax: {
url: "/listallergiesajax",
dataType: 'json',
data: function(term) {
return {
q: term
};
},
results: function(data, page) {
return {
results: $.map(data, function(item) {
return {
text: item.text,
id: item.id
}
})
};
},
},
initSelection: function(element, callback) {
$.ajax("/listallergiesajax", {
dataType: "json"
}).done(function(data) {
callback(data.results[0]);
});
}
});
最佳答案
Select2 v3.5.2 使用 initSelection
方法。 Select2 v4 有不同的方法。
有关如何升级(initSelection
和其他内容)的信息,请参阅 https://select2.org/upgrading/migrating-from-35#removed-the-requirement-of-initselection .
关于jquery - select2 - 初始化选择错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29919108/