I am using Select2 to load data remotely and it is bringing the results normally, however when selecting one of the options returned all exist and I could not identify why, it follows the code:
Javascript
$('.js-data-example-ajax').select2({
ajax: {
url: "/Home/PopularUsuarios",
dataType: 'json',
type: "post",
delay: 250,
theme: 'clasic',
data: function (params) {
return {
objPesquisa: params.term, // search term
};
},
processResults: function (data, params) {
params.page = params.page || 1;
data.forEach(function (d, i) { d.id = i; })
return {
results: data,
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
minimumInputLength: 1,
templateResult: function (data) {
if (data.loading) return data.text;
var markup = '<option value="' + data.Matricula + '">' + data.Nome + '</option>'
return markup;
},
templateSelection: function (data) {
return data.full_name || data.text;
}
});