[英]Why can't I choose value from select2?
All data is shown and correct but I can't select any value from select2 dropdown. 所有数据均显示正确,但我无法从select2下拉列表中选择任何值。
What is wrong with my code? 我的代码有什么问题?
jQuery(document).ready(function() {
jQuery('#basic').select2({
minimumInputLength: 0,
multiple: false,
query:function(options) {
var result = ymaps.suggest(options.term).then(function (items) {
var data = [];
var output = {
results : [],
more : null
};
for (var index = 0; index < items.length; ++index) {
console.log(items[index]);
data.push({
id: index,
text: items[index]['displayName'],
})
}
output.results = data;
output.more = true;
console.log(output);
options.callback(output);
});
}
});
jQuery('#basic').on('select2:select', function () {
console.log('on select: ' + jQuery(this).val());});
} }
After doing R&D on select2
I found that query
method is deprecated
(See https://select2.org/configuration/options-api ) so try to use ajax method. 在
select2
上进行研发之后,我发现query
方法已被deprecated
(请参阅https://select2.org/configuration/options-api ),因此请尝试使用ajax方法。
Also there is one more issue when I opened the debugger I found that other select2
drop down (I mean select2
used on https://select2.org/ ) is adding options under drop down but in your case your select box is empty. 当我打开调试器时,还有一个问题,我发现其他
select2
下拉菜单(我的意思是在https://select2.org/上使用的select2
)正在下拉菜单下添加选项,但是在您的情况下,选择框为空。
I would suggest try asking on their community https://forums.select2.org/ 我建议尝试在其社区中提问https://forums.select2.org/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.