我正在使用React-Redux做一个项目,我对它很新。 我有一个看起来像这样的JSON对象
{
"topLevel": {
"
"Title": "Title Text",
"Content": "",
"Categories": [
"123",
"456",
"789",
]
},
"NextLevel": [
{
"ID": "123",
"Name": "ValentinesDay",
"Type": 0,
]
},
{
"ID": "456",
"Name": "Family Meals",
"Title": "Family Meals",
},
{
"ID": "999",
"Name": "sample",
"Title": "sample",
},
{
"ID": "789",
"Name": "sample",
"Title": "sample",
},
I need to find a way to iterate through the TopLevel and find matchingIds in the second one and display those elements on the DOM.
My reducers looks like this now
switch (action.type) {
case RECEIVE_PRODUCTS:
return {
...state,
...action.products.NextLevel.reduce((obj, product) => {
obj[product.ID] = product;
return obj;
}, {})
}
default:
return state
这将显示NextLevel对象中的所有元素。如何包含一个条件,确保我只提取已在第一级列出的IDS?