I'm 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 the 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')