I have a multiselect dropdown with below data:
var fruitArray = [];
var fruitGreen = [];
var fruitNotGreen = [];
fruitGreen = {
“text”: “Green”,
“children”: [
{ “id”: “Watermelon”, “text”: “Watermelon” },
{ “id”: “Lime”, “text”: “Lime” },
{ “id”: “Guava”, “text”: “Guava” },
{ “id”: “Avocado”, “text”: “Avocado” },
{ “id”: “Kiwi”, “text”: “Kiwi” },
]};
fruitNotGreen = {
“text”: “Not Green”,
“children”: [
{ “id”: “Apple”, “text”: “Apple” },
{ “id”: “Orange”, “text”: “Orange” },
{ “id”: “Berries”, “text”: “Berries” },
{ “id”: “Grape”, “text”: “Grape” },
{ “id”: “Pineapple”, “text”: “Pineapple” },
]};
fruitArray.push(fruitGreen, fruitNotGreen);
$(’.select2’).select2({
placeholder: ‘-- Select Fruits --’,
allowClear: true,
maximumSelectionLength: 50,
dropdownAutoWidth: true,
data: fruitArray,
multiple: true,
closeOnSelect: false
});
How to Insert Options with Ajax while Having Option Group? Please help