First time using underscore and I am stuck and cannot find an example.
My data is:
[{
"store_name": "Store 1",
"franchisee_id": "id01",
"dish_menu": "Breakfast",
"dish_count": "17"
}, {
"store_name": "Store 1",
"franchisee_id": "id01",
"dish_menu": "Light Meals",
"dish_count": "7"
}, {
"store_name": "Store 1",
"franchisee_id": "id01",
"dish_menu": "Sandwiches",
"dish_count": "12"
}, {
"store_name": "Store 2",
"franchisee_id": "id02",
"dish_menu": "Breakfast",
"dish_count": "7"
},
............
]
I have managed (with some help from here) to pull the distinct store_name
with the following chained command and then place it into a HTML statement I am building:
var stores = _.chain(json).pluck("store_name").sort().uniq(true).value();
var tempHTML = "";
stores.forEach(function (entry) {
tempHTML = tempHTML + '<option value="' + entry + '">' + entry + '</option>';
});
But I am trying to match the franchisee_id
to the distinct store_name
and essentially build my HTML like below:
stores.forEach(function (entry) {
tempHTML = tempHTML + '<option value="' + FRANCHISEE_ID + '">' + STORE_NAME + '</option>';
});
Is there a way to _.pluck
a value for franchisee_id using the store_name value? There is a 1:1 relationship between these two fields so even getting the "first found" franchisee_id is fine. Thanks!