【发布时间】:2013-08-23 04:20:50
【问题描述】:
使用以下html:
<input type='hidden' id='cantseeme'>
动态创建 Select2 控件并添加我的选项没有问题:
// simplified example
var select2_ary = [];
select2_ary.push({
id : "one",
text : "one"
});
select2_ary.push({
id : "two",
text : "two"
});
$("#cantseeme").select2({
placeholder : "Pick a number",
data : select2_ary
});
但是,我似乎无法弄清楚如何以这种方式添加optgroups。我在 github 上找到了 this 讨论,在博客上找到了 this 文章,但前者似乎没有讨论动态的 optgroup 添加,我根本无法理解后者。
有人有什么想法吗?
【问题讨论】:
标签: javascript jquery jquery-select2