通过使用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);