I have a problem with Selectize.js, where it is taking a long time to create the structure, I make a request in my backend where it returns about 1000 data, which does not take 500ms of response, but when adding the options in my Selectize.js using addOption and addItem takes more than 10 seconds. Is there a way to improve this or a faster alternative?
Javascript:
$('#my-select').selectize({
sortField: 'text'
});
//initialize request
var request = $.ajax({
url: "/request_data.php",
type: "post",
dataType: 'json',
});
// Callback handler that will be called on success
request.done(function (response, textStatus, jqXHR) {
response.forEach(function (data) {
///////////////////////////////////HERE TAKE A LONG TIME
form_field_select[0].selectize.addOption({ value: data.id, text: data.text });
form_field_select[0].selectize.addItem(data.id);
});
});
HTML
<select id="my-select">
<option value="">Select any option</option>
</select>