質問

i am using select2 multi select dropdown, and it works perfectly but my problem is, i want to categorise the drop down list of the same. Here is my code

<script src="/static/select2.js"></script>
<input type="hidden" id="test" value=""/>

and js

$(test).select2({
data:data,
multiple: true,
width: "100%",
placeholder:"None Selected",
closeOnSelect:false,
});
役に立ちましたか?

解決

This should work:

$(test).select2({
  data: 
    [
      {
        text: 'GREETINGS',
        children: 
        [
          { 'id': 1, text: 'hai' }, 
          { 'id': 2, text: 'hellow'}, 
        ]
      }, 
      {
        text: 'QUESTIONS',
        children: 
        [
          { 'id': 3, 'text': 'yes' }, 
          { 'id': 4, 'text': 'no'  }
        ]
      }
    ],
  multiple: true,
  width: "100%",
  placeholder: "None Selected",
  closeOnSelect: false,
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top