How to handle data that does not have id or text data fields
Opened this issue · 1 comments
cdesch commented
How do I handle with select2 data that does not have id
and text
fields?
Data like this will work:
var data = [
{
id: 0,
text: 'enhancement'
},
{
id: 1,
text: 'bug'
},
{
id: 2,
text: 'duplicate'
},
{
id: 3,
text: 'invalid'
},
{
id: 4,
text: 'wontfix'
}
];
$('#request_for_proposal_geo_path_counties').select2({
theme: "bootstrap",
data: data
});
But data like this won't:
var data = [
{
"fips": "02",
"name": "Alaska",
"zip_codes": [],
"counties": [],
"population_0": 752680,
"population_5": 698356,
"population_18": 565916,
"population_21": 534794
},
{
lndl commented
Hi @cdesch,
Unfortunately, there is nothing to custom the shape of the results. It should have some kind of function hook in this place: https://github.com/lndl/select2_simple_form/blob/master/app/assets/javascripts/select2_simple_form/initializers.select2_simple_form.js#L89
If you want, you can do that change and I will merge it thankfully!