在段對象中,我有一個CategoryId
- 就像一個外鍵。 現在,我想將每個部分複製到匹配的類別對象中。擴展一個對象(嵌套)
來源:
var sections = [{title:"FirstSection", CategoryId : 1},
{title:"SecondSection", CategoryId : 1},
{title:"ThirdSection", CategoryId : 2}];
var categories = [{title:"Cat1", Id : 1},
{title:"Cat2", Id : 2}];
結果是這樣的:
categories = [{title:"Cat1",
Id : 1,
sections : [{title:"FirstSection", CategoryId : 1},
{title:"SecondSection", CategoryId : 1}]
},
{title:"Cat2",
Id : 1,
sections: [{title:"ThirdSection", CategoryId : 2}]
}];
與CategoryId = 1
所有部分現在是在使用id = 1
也許類別的部分陣列我正在尋找錯誤的關鍵字,但我找不到解決方案。
這兩個簡單的實現了循環做了什麼你確切的問題是? – 2013-04-06 20:31:58
這些都是對象的數組,你的代碼中沒有任何與JSON有關的東西。 – 2013-04-06 20:47:04