0
我想這組JSON underscore.js使用的category
使用的GroupBy使用嵌套的JSON對象
[{
"brand": "Brand3",
"category": {
"popularity_index": 7,
"BroadCategory ": "BroadCategory4",
"MainCategory": "MainCategory410",
"GeneralCategory": "GeneralCategory41"
},
"description": "colonialism",
"discount": 17,
"id": 9
}, {
"brand": "Brand2",
"category": {
"popularity_index": 5,
"BroadCategory ": "BroadCategory2",
"MainCategory": "MainCategory210",
"GeneralCategory": "GeneralCategory21"
},
"description": "desc2",
"discount": 15,
"id": 2
}]
我通過underscore.js - _.groupBy nested attribute去BroadCategory
屬性,但是這裏面的JSON數組location
我試着像這樣:
var grpArray = _.groupBy(products, function (element) {
return element.category.BroadCategory;
})
但它不工作。爲什麼我無法訪問BroadCategory
?
Ahh.My bad.That接近。 :) 謝謝 –