Select2 maps data objects to <option>
and <optgroup>
tags using the following logic
A data object (what is returned in the list) that looks like
{
'id': 'value-here',
'text': 'text-here'
}
Will be mapped to an <option>
that looks like
<option value="value-here">text-here</option>
A data object that looks like
{
'text': 'label-here',
'children': [data_object, data_object]
}
Will be mapped into an <optgroup>
that looks like
<optgroup label="label-here">
<!-- HTML for the `children` -->
</optgroup>
So the data object that you are looking to return is
{
'text': 'group',
'children': [
{
'id': 'imageName',
'text': 'value 1'
},
{
'id': 'imageName',
'text': 'value 1'
}
]
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…