【发布时间】:2015-10-05 18:53:50
【问题描述】:
我将 select2 与 spring mvc 一起使用。我从控制器中获取了需要在此处显示的数据选项。但我希望将它们分组为 optgroup,并且我希望将图像附加在其中,可以手动插入,如下所示: -
<optgroup label="group">
<option value="imageName">value 1</option>
<option value="imageName">value 1</option>
</optgroup>
其中 imageName 是图像的名称。我想要 : 1) json 中的组选项。 2)在json中提供这个image属性,这样select2就可以形成数据了。
代码如下:
$("#my-select").select2({
data : [ {
id : 0,
text : 'enhancement'
}, {
id : 1,
text : 'bug'
}, {
id : 2,
text : 'duplicate'
}, {
id : 3,
text : 'invalid'
}, {
id : 4,
text : 'wontfix'
} ]
});
我正在从我的对象手动创建我的 json。所以我可以在这里提供任何数据。有什么建议吗?
【问题讨论】:
标签: javascript jquery jquery-select2