How to preload options into the dropdown
I have tried:
Preselecting options in an remotely-sourced (AJAX) Select2
for (var key in data) {
if (data.hasOwnProperty(key)) {
var option = new Option(data[key].text, data[key].id, false, false);
hardwareSelect.append(option).trigger(‘change’);
}
};
hardwareSelect.trigger({
type: ‘select2:open’,
params: {
data: data
}
});
The result is that my select2 dropdown only shows one selected option.
and i have tried:
hardwareSelect.select2({ data: data })
The result is that my default search ajax (remote data) select2 will not work.