0
I am trying to make an ajax query to an api to dynamically create a Select2.
The api is returning data normally, but only the "No Results found" message appears in select.
HTML
<select name='produtos[]' multiple="multiple" id="selProdutos">
</select>
Jquery
$("#selProdutos").select2({
maximumSelectionLength: 2,
ajax: {
url: 'api/produtos/1',
type: 'GET',
dataType: 'json',
results: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.name,
id: item.id
}
})
};
}
}
}).material_select('destroy')