Hi,
I have a seelct2 , I am calling an API to load data , once the data is loaded I would like to search on the preloaded data. But for some reason data is not getting loaded in select2 . Below is my code:
$(document).ready(function () {
$.ajax({
url: '/Service/GetCountries',
dataType: 'json',
type: "GET",
delay: 250,
data: ({
}),
success: function (data) {
return data;
}
}).then(function (response) {
console.log(response);
$('.country-select').select2({
width: 'resolve',
placeholder: "Country",
processResults: function (response) {
return {
results: $.map(response, function (item) {
return {
text: item.name,
id: item.alpha2Code
}
})
}
}
});
});
});
Please let me know what I am doing wrong here.
Thanks