When i geve to Select 2 a remote Ajax (with groups) the 'selected' option is not set in aria-selected , that load only ID and text but no selected option.
{
"results":[
{
"text":"User",
"children":[
{
"id":37,
"text":"Victor",
"selected":true
},
{
"id":153,
"text":"Manuel",
"selected":false
}
]
},
{
"text":"Support",
"children":[
{
"id":39,
"text":"Robert",
"selected":true
},
{
"id":36,
"text":"Rudolf",
"selected":false
},
{
"id":202,
"text":"Claus",
"selected":false
}
]
}
]
}
This is my Javascript:
$('#my_select2').select2({
allowClear: true,
minimumInputLength: 0,
maximumSelectionLength: 0,
multiple: true,
closeOnSelect: true,
delay: 250,
ajax: {
type: "POST",
url: "my_json.json",
dataType : 'json',
cache: false
},
});
i read that i need process the result but when i put this code then i dont have results ...
processResults: function (data, params) {
return {
results: jQuery.map( data.children, function( children ) {
var arr = {id:children.id,text:children.text};
return arr;
}),
};
}