gpt4 book ai didi

javascript - Select2.js v4.0 : how set the default selected value with a local array data source?

转载 作者:数据小太阳 更新时间:2023-10-29 05:02:18 25 4
gpt4 key购买 nike

通过使用 select2.js v4插件,当我使用本地数组数据作为源时,如何设置默认选择值?

以这段代码为例

var data_names = [{
id: 0,
text: "Henri",
}, {
id: 1,
text: "John",
}, {
id: 2,
text: "Victor",
}, {
id: 3,
text: "Marie",
}];

$('select').select2({
data: data_names,
});

如何设置id 3为默认选中值?

最佳答案

$('.select').select2({
data: data_names,
}).select2("val",3);

关于javascript - Select2.js v4.0 : how set the default selected value with a local array data source?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31654200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com