Vineeth Mohan
Vineeth Mohan

Reputation: 19283

Multi options in select2

I am trying to use select2 to get remote JSON data and display it with mutli levels. http://ivaynberg.github.io/select2/index.html

This is my response

{
  "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"
    }
  ]
}

I want to show the result in Multi-Value format - http://ivaynberg.github.io/select2/index.html#multi

So far i am able to fetch data from server side , but then i have no idea how to enable the multi select option.

Upvotes: 0

Views: 793

Answers (1)

Vineeth Mohan
Vineeth Mohan

Reputation: 19283

JSON in following format will work fine

Related issue - 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"
                      }]
        }
           ]    
}    

Upvotes: 1

Related Questions