How to set array value into textfield using selectize.js

Hello I have a problem regarding selectize. I tried and test this code to ensure that I get a list of email coming from the database.

for(var i = 0; i < e.email.length; i++){
  console.log(e.email[i]);
  var list = e.email[i];
}

The results are fine and I get what I want. But when using selectize...

var $el = $("#poc-email").selectize();
var control = $el[0].selectize;
control.setValue(list);

It doesnt work. I also tried..

addOption(list);
refreshItems();

and also I tried..

addItem(list);

but it doesnt work.

Thanks for the help.

Upvotes: 2

Views: 563

Answers (1)

MY SOLUTIONS IS:

for(var i = 0; i < e.email.length; i++){
            control.addOption({text:e.email[i].emails, value:e.email[i].emails});
            control.addItem(e.email[i].emails);
            control.refreshItems();
          }

Upvotes: 2

Related Questions