How do I set the selectize.js options list programmatically?

后端 未结 3 663
臣服心动
臣服心动 2021-02-01 03:46

I know how to set the optionList on Initiliaztion but how do I set it programmatically?

I have an inviteList array:

$(\"#s         


        
3条回答
  •  离开以前
    2021-02-01 04:08

    I know this is an old question but as of 2021 I have found this to be the simplest way to achieve this:

    Building on @byte255's answer above, you only need to use the clearOptions method and addOption method.

    let selectize = $("#select-invite")[0].selectize;
    
    selectize.clearOptions();
    
    let newOptions = [
        {
            text: 'Option One',
            value: 1
        },
        {
            text: 'Option Two',
            value: 2
        }
    ]
    
    selectize.addOption(newOptions);
    
    

提交回复
热议问题