Selectize.js manually add some items

前端 未结 6 1788
生来不讨喜
生来不讨喜 2020-12-15 15:39

I want add some items to a selectized input after user clicks on a button. The input data are loaded via Ajax. When I call addItem(value) no thing happens. But if I try to t

6条回答
  •  鱼传尺愫
    2020-12-15 16:24

    If you want to be more flexible then you can use the length like this.

    var $select = $(document.getElementById('Your-ID'));        
    var selectize = $select[0].selectize;
    var count = selectize.items.length + 1;
    selectize.addOption({ value: count, text: 'value-here' });
    selectize.addItem(count);
    

提交回复
热议问题