来自官方文档的加载数组数据示例对我不起作用。
https://jsfiddle.net/Jngai1297/v64rwj7b/7/
HTML
<select class="js-example-data-array-selected">
<option value="2" selected="selected">duplicate</option>
</select
的javascript
var hidata = [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }, { id: 3, text: 'invalid' }, { id: 4, text: 'wontfix' }];
$(".js-example-data-array").select2({
data: hidata
})
$(".js-example-data-array-selected").select2({
data: hidata
})
示例直接来自doc,外部资源也是正确的。半天被黑客攻击并四处搜索,一无所获。
答案 0 :(得分:-1)
$(document).ready(function(){
var airPorts = [
{id:0,text:'airport one'},
{id:1,text:'airport two'},
{id:2,text:'airport three'},
{id:3,text:'airport four'},
];
$('.select2').select2({
data: airPorts,
});
});