我有有效載荷,其表示正深深嵌套的樹狀結構,它看起來像..(你可以把部分陣列作爲一棵樹上兒童)終極版減速如何更新歸州兒童
const data = {
id: 123,
sections: [{
id: 1,
sections:[{ id: 4, sections: [ { id: 5, sections: [] } ] }]
}, {
id: 2,
sections:[]
}, {
id: 3,
sections:[]
}]
};
歸有效載荷A的狀態如下
{
"entities": {
"sections": {
"1": { "id": 1, "sections": [ 4 ] },
"2": { "id": 2, "sections": [] },
"3": { "id": 3, "sections": [] },
"4": { "id": 4, "sections": [ 5 ] },
"5": { "id": 5, "sections": [] }
},
"menu": {
"123": { "id": 123, "sections": [ 1, 2, 3 ] }
}
},
"result": 123
}
如果用戶要展開第5部分,我將關閉並從服務器加載更多子項。有效載荷B,從服務器返回時,歸一化會是什麼樣子
{
"entities": {
"sections": {
「6」: { "id": 6, "sections": [] },
},
"menu": {
"1234」: { "id": 1234, "sections": [ 6 ] }
}
},
"result": 1234
}
我如何寫一個減速器結合(合併/圖等)歸一化的有效載荷的和標準化的有效載荷B上的新的終極版商店狀態如下所示。 ..
{
"entities": {
"sections": {
"1": { "id": 1, "sections": [ 4 ] },
"2": { "id": 2, "sections": [] },
"3": { "id": 3, "sections": [] },
"4": { "id": 4, "sections": [ 5 ] },
"5": { "id": 5, "sections": [6] },
「6」: { "id": 6, "sections": [] }
},
"menu": {
"123": { "id": 123, "sections": [ 1, 2, 3 ] }
}
},
"result": 123
}
感謝。這幫助我簡化了我的想法。 –