I know how to set the optionList
on Initiliaztion but how do I set it programmatically?
I have an inviteList array:
$("#select-invite").options(inviteList);
You can add options like this: var $select = $(document. getElementById('mySelect')). selectize(options); var selectize = $select[0].
Remove the option select[0]. selectize. removeItem(selectedValue); select[0].
You can use load method to set options via programmatic API. You may also want to call clear and clearOptions methods to reset selected values and old options.
Here is how to put it all together:
var selectize = $("#select-invite")[0].selectize; selectize.clear(); selectize.clearOptions(); selectize.load(function(callback) { callback(inviteList); });
Please note that inviteList should be an array of objects that have properties configured in valueField and labelField options when select was initialized. For example, here is how inviteList should look like with default valueField and labelField options:
var inviteList = [ { text: 'Option One', value: 1 }, { text: 'Option Two', value: 2 } ];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With