计算selectize.js中的选项数量

时间:2015-09-04 06:31:37

标签: javascript jquery html select

如何使用selectize.js计算下拉列表中的选项数量?

$('#MyDrop option').length;

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

以上不适用于选择!

2 个答案:

答案 0 :(得分:4)

获取所有选择

的选项

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

获取对象的所有键

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

答案 1 :(得分:3)

使用Selecize API,您可以使用此方法获取选项:

@Before
public void setup(){
    DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("noReset","true");
            capabilities.setCapability("fullReset","false");
            capabilities.setCapability("automationName","Appium");
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("VERSION", "5.1.1");
            capabilities.setCapability("deviceName", "LG Nexus 5");
            capabilities.setCapability("appPackage", "com.packageName");
            capabilities.setCapability("appActivity", "ui.activity.SplashScreenActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@Test
public void sampleTest(){
//Testing Code Only
}

//To Exit/Quit close the driver
    @After
    public void teardown() {
        if (driver != null)
            driver.quit();
    }

然后遍历对象来计算它们:

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