Skip to content

Instantly share code, notes, and snippets.

@pablomp
Created November 13, 2013 11:17
Show Gist options
  • Save pablomp/7447436 to your computer and use it in GitHub Desktop.
Save pablomp/7447436 to your computer and use it in GitHub Desktop.
Combo Select2 con valores dinámicos desde un JSON
$j('#e1').select2({
placeholder: "Seleccione municipio",
allowClear: true,
ajax: {
url: '/vct/json/jsonMunicipios.php',
dataType: 'json',
data: function (term) {
return {
term: term
};
},
results: function (data) {
var results = [];
$j.each(data.results, function(index, item){
results.push({
id: item.id,
text: item.text,
coordendadaLat: item.coordinates[1],
coordendadaLong: item.coordinates[0]
});
});
return {
results: results
};
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment