选择2:远程数据(AJAX)不要设置'选择'按键

时间:2018-03-21 11:16:41

标签: javascript jquery jquery-select2

当我选择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;
                                  }),
                                };
                              }

0 个答案:

没有答案