Created
October 25, 2014 10:52
-
-
Save trkrameshkumar/5d3bb6f224448dee8fc6 to your computer and use it in GitHub Desktop.
select2 ajax example with formated result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#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