Skip to content

Instantly share code, notes, and snippets.

@jorgeandrescastro
Created September 20, 2017 22:17
Show Gist options
  • Select an option

  • Save jorgeandrescastro/8d99081f48922ca7d81b872f08f68135 to your computer and use it in GitHub Desktop.

Select an option

Save jorgeandrescastro/8d99081f48922ca7d81b872f08f68135 to your computer and use it in GitHub Desktop.
$lookup = $('.js-lookup');
$lookup.select2({
ajax: {
dataType: 'json',
delay: 250,
data: function(params) {
return {
search: params.term
}
},
processResults: function(data) {
return {
results: $.map(data.data, function(children, group) {
return {
text: group, children: $.map(children, function (text, value) {
return { id: value, text: text }
})
}
})
// results: $.map(data.data, function(text, value) {
// return { id: value, text: text }
// })
};
},
cache: true
},
width: '100%',
minimumInputLength: 2,
theme: 'bootstrap',
allowClear: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment