使用selectize js清除后如何在输入标签中设置值

问题描述

早上好我是 selectize.js 的新手我想在使用 selectize.js 的清除功能后在输入标签中设置值这里是我的代码

$('#selectize-update-endUser').selectize()[0].selectize.clear()
const endUsers = "america,japan";
$('#selectize-update-endUser').val(endUsers);
$('#selectize-update-endUser').selectize({
  plugins: ['remove_button'],delimiter: ',',persist: false,create: true,});

请帮我谢谢

解决方法

我已经解决了问题 这是代码

//set the value to a constant variable and use split function to make the two string separated by comma will become array
 const endUsers = "america,japan".split(',');

//intialize the input tag into selectized        
$('#selectize-update-endUser').selectize({
            plugins: ['remove_button'],delimiter: ',',persist: false,create: true,});

  //clear the input that selectized      
  $('#selectize-update-endUser').selectize()[0].selectize.clear()

     //set the value into the input tag that selectized Note: use for loop if the value given is separated in delimeter 
   for (const user of endUsers) {
            $('#selectize-update-endUser').selectize()[0].selectize.createItem(user);
        }

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...