微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决使用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);
        }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。