Is it possible to display the region_name in a select_one_dropdown, but save the region_nr in the database?
The code for pulling the data is:
_.chain(context).pluck(‘region_name’).uniq().map(function(region_name){
return {data_value:region_name, display:{title: {text: region_name} } };
}).value()
I’ve tried changing; data_value: region_nr, without any luck.
I think the problem with your query is that you have the .pluck(‘region_name’). What that basically does is filter out anything except ‘region_name’ (i.e. you lose the rich object with e.g. the .region_nr property, and just have the string value of region_name available in your map() function…
Of course, if you leave out the pluck(‘region_name’), then your uniq() function will have no effect resulting in duplicates.
Hello again,
Just in case you were wondering how to get your uniq() to work, you can feed it with a function that determines how to evaluate uniqueness, e.g.
_.chain(context)
.uniq(function(x) {
return x.region_name
})
.map(function(place){
return {
data_value:place.region_nr,
display:{title: {text: place.region_name} } };
}).value()
…you could also determine uniqueness based on x.region_nr for a slight performance benefit (assuming it is a number type).
Note also, that your return object can include more properties, in case you want to use it in a choice_filter, e.g. when you have sub-regions you might want to include the parent_region as a property in the result of the map() function…