Created
February 20, 2015 21:47
-
-
Save jheth/22a0e7fb175c1a09c7d6 to your computer and use it in GitHub Desktop.
select2 ajax
This file contains 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
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