1
使用後normalizr
庫我在我的應用程序的終極版聲明如下規範化JSON對象結果:如何過濾沒有數組的標準化嵌套JSON數據?
{
sports: {
byId: {
1: {
id: 1,
name: 'Soccer',
slug: 'soccer'
},
2: {
id: 2,
name: 'Basketball',
slug: 'basketball'
},
3: {
id: 3,
name: 'American Football',
slug: 'american-football'
}
},
allIds: [
'1',
'2',
'3'
]
},
competitions: {
byId: {
'1': {
id: 1,
name: 'Competition 1',
short_name: 'Comp 1',
slug: 'comp-1',
sport: 1,
status: {
is_live: false
}
},
'2': {
id: 2,
name: 'Competition 2',
short_name: 'Comp 2',
slug: 'comp-2',
sport: 1,
status: {
is_live: true
}
},
'3': {
id: 3,
name: 'National Basketball League',
short_name: 'NBA',
slug: 'national-basketball-league',
sport_slug: 'basketball',
sport: 3,
status: {
is_live: true
}
}
},
allIds: [
'1',
'2',
'3'
]
}
我想達到什麼:我想過濾的competitions
列表/由sports
分類。
我該怎麼做?
另外我希望能夠通過組competitions
它的status.is_live
。
那麼,如何可以通過sport
是status.is_live
等於真實competitions
status.is_live
得到competitions
擊穿的名單等於假的?
任何幫助表示讚賞!謝謝
感謝你的幫助。我嘗試過這一點,我認爲它沒有關於「運動」的狀態/ is_live參考。 '讓filteredCompetitions = _.chain(比賽) .groupBy( '運動') 。價值() //返回最終值 _.forEach(filteredCompetitions,函數(價值,鍵){ filteredCompetitions [ key] = _.groupBy(filteredCompetitions [key],function(item){ return item.status.is_live; }); }); console.log(filteredCompetitions)' 也許有更優雅的方式來做到這一點? –
檢查更新後的答案 – casraf