I am using select2 with spring mvc. I got the data from my controller that I need to display here in terms of options. But I want them to be grouped as optgroup and also I want images to be appended in it which can be inserted manually as given below : -
<optgroup label="group">
<option value="imageName">value 1</option>
<option value="imageName">value 1</option>
</optgroup>
Where imageName is the name of image. I want to : 1) Group options in json. 2) Provide this image attribute in json so that select2 can form the data.
Here is the code :
$("#my-select").select2({
data : [ {
id : 0,
text : 'enhancement'
}, {
id : 1,
text : 'bug'
}, {
id : 2,
text : 'duplicate'
}, {
id : 3,
text : 'invalid'
}, {
id : 4,
text : 'wontfix'
} ]
});
I am creating my json manually from my objects. So I can provide any data here. Any suggestions ?