select2中的多个选项

时间:2013-05-11 16:53:37

标签: javascript jquery-select2

我正在尝试使用select2来获取远程JSON数据并使用mutli级别显示它。 http://ivaynberg.github.io/select2/index.html

这是我的回复

{
  "Company": [
    {
      "name": "athenahealth Inc"
    },
    {
      "name": "Localiza Rent a Car"
    },
    {
      "name": "M and B Switchgears"
    }
  ],
  "Functional": [
    {
      "name": "arranger"
    },
    {
      "name": "ambassadors"
    }
  ],
  "Persons": [
    {
      "name": "Moustapha al"
    },
    {
      "name": "Saleh al"
    }
  ]
}

我想以多值格式显示结果 - http://ivaynberg.github.io/select2/index.html#multi

到目前为止,我能够从服务器端获取数据,但后来我不知道如何启用多选选项。

1 个答案:

答案 0 :(得分:1)

以下格式的JSON可以正常工作

相关问题 - https://github.com/ivaynberg/select2/issues/58

{ "Data" : [ {
            "id" :1 ,
            "text" : "Subsection" ,
            "children" : [{
                    "id" : 2,
                    "text" : "Paru"
                      },
                      {
                    "id" : 3,
                    "text" : "Vinu"
                      }]
        },
            { "id" : 4 ,
            "text" : "Family" ,
            "children" : [{
                    "id" : 5,
                    "text" : "ChildVM"
                      },
                      {
                    "id" : 6,
                    "text" : "ChildPM"
                      }]
        }
           ]    
}