#javascript #input #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,
});
Пожалуйста, помогите мне, спасибо
Ответ №1:
Я решил проблему Вот код
//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);
}