当我选择2远程Ajax(带有群组)时,选择'选项未在aria-selected中设置,仅加载ID和文本,但没有选择选项。
{
"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
}
]
}
]
}
这是我的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
},
});
我读到我需要处理结果但是当我把这个代码放在那时我没有结果......
processResults: function (data, params) {
return {
results: jQuery.map( data.children, function( children ) {
var arr = {id:children.id,text:children.text};
return arr;
}),
};
}