【发布时间】:2015-10-17 16:53:48
【问题描述】:
使用select2.jsv4插件,当我使用本地数组数据作为源时,如何设置默认选择值?
例如使用此代码
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为默认选择值?
【问题讨论】:
-
$("#id").select2().select2("val", 'oneofthevaluehere');
-
从 v4.1 开始,只需执行 {id: 3, text: "Marie", selected: true}。
标签: javascript jquery jquery-select2 jquery-select2-4