Select2: loading selected values

后端 未结 1 2039
情书的邮戳
情书的邮戳 2021-02-11 04:14

Im trying to load the selected values from the database into my multiple select box.

When I load the option initially from the database, It work perfect.

<
相关标签:
1条回答
  • 2021-02-11 05:16

    So after a little help from Mr Arun P Johny, I finaly got to the very simple answer.

    Maybe I dont fully grasp it yet, but is I understand correctly, you have to approach the loading differently depending if you are creating your Select2 from a input or a select.

    Mine was created from a select so getting the data back from the AJAX call, I simply used the array containing the ID values of the selected items and passed it through like this

     $('#media_keywords').select2().select2('val', keywordArray)
    

    keywordArray being the array of IDs.

    0 讨论(0)
提交回复
热议问题