Skip to content

Instantly share code, notes, and snippets.

@jheth
Created February 20, 2015 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jheth/22a0e7fb175c1a09c7d6 to your computer and use it in GitHub Desktop.
Save jheth/22a0e7fb175c1a09c7d6 to your computer and use it in GitHub Desktop.
select2 ajax
this.$().select2({
ajax: {
url: "/search",
type: 'GET',
dataType: 'json',
delay: 250,
data: function (term) {
return {
q: term,
id: params.id,
source: 'crm'
};
},
results: function (data, page) {
return {
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
results: $.map(data, function (item) {
return {
id: item.internalId,
text: item.title
};
})
};
},
cache: true
},
minimumInputLength: 3
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment