admin管理员组

文章数量:1244389

how to count number of options in dropdown using selectize.js?

$('#MyDrop option').length;

$('#MyDrop option').size();

Above ones are not working with selectize !

how to count number of options in dropdown using selectize.js?

$('#MyDrop option').length;

$('#MyDrop option').size();

Above ones are not working with selectize !

Share Improve this question edited Nov 9, 2015 at 19:26 pnuts 59.5k11 gold badges91 silver badges141 bronze badges asked Sep 4, 2015 at 6:31 Abubakar IkramAbubakar Ikram 4531 gold badge9 silver badges24 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 8

Get all options of selectize

let options = $('#selectElem')[0].selectize.options;

Get all keys of object

let count = Object.keys(options);
console.log(count.length);

Using the Selecize API, you can get options with this method:

options = $('#my_select_widget')[0].selectize.options;

Then loop through the object to count them:

var cnt = 0;
for(k in options){
    cnt++;
}
console.log(cnt);

本文标签: javascriptCount number of options in selectizejsStack Overflow