Select2: how to set data after init?

后端 未结 7 1872
醉梦人生
醉梦人生 2021-02-06 22:33

I need to set an array of data after initializing select2. So I want to make something like this:

var select = $(\'#select\').select2({});
select.data([
  {id: 1         


        
7条回答
  •  粉色の甜心
    2021-02-06 23:01

    Make an element and bind select2 to that. Using .select2 on a regular select box doesn't let you play with the data, it just mostly gives you the UI and post-selection methods.

    Source: Select2 Documentation

提交回复
热议问题