Ok, I\'m sure there\'s something simple set wrong here but I\'m not 100% what it is.
So I am trying to use Select2 AJAX method as a way of users to search a database
Like Dropped.on.Caprica said: Every result item needs an unique id.
So just assign every result id
an unique number:
$('#searchDriver').select2({
ajax: {
dataType: 'json',
delay: 250,
cache: true,
url: '/users/search',
processResults: function (data, params) {
//data is an array of results
data.forEach(function (d, i) {
//Just assign a unique number or your own unique id
d.id = i; // or e.id = e.userId;
})
return {
results: data
};
},
},
escapeMarkup: function (markup) { return markup; },
minimumInputLength: 1,
templateResult: formatRepo,
templateSelection: formatRepoSelection
});