Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
select2 ajax example with formated result
$("#selector").select2({
width: "200px",
placeholder: "Search for a item",
minimumInputLength: 3,
ajax: {
url: "/url",
dataType: "json",
data: function(term, page) {
return {
q: term,
max: 10
};
},
results: function(data) {
var myResults;
myResults = [];
$.each(data, function(index, item) {
myResults.push({
id: item.id,
text: item.email + " " + "[ " + item.name + " ]"
});
});
return {
results: myResults
};
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment