我想創建一個陣列結構與子實體這樣的 - >變化陣列格式
$scope.groups = [
{
"categories": [
{
"name": "PR",
"sortOrder": 0,
"type": "category"
}
],
"name": "DEPT 1",
"sortOrder": 0,
"type": "group",
"id": "-JY_1unVDQ5XKTK87DjN",
"editing": false
}
];
從數組這麼想的有孩子的實體,但所有項目都在一個對象列出像這個 - >
$scope.groups = [
{
"name": "PR",
"sortOrder": 0,
"type": "category"
},
{
"name": "AD",
"sortOrder": 3,
"type": "category"
},
{
"name": "DEPT 2",
"sortOrder": 1,
"type": "group",
"id": "-JYZomQKCVseJmaZoIF9",
"editing": false,
"categories": []
},
];
有什麼可能的辦法嗎?
「類別」是否以某種方式與「部門」相關聯。或者你是否想將數組中的'categories'聚集在一個數組中,並將其他對象保持原樣並最終將它們封裝在一個JavaScript對象中? – 2014-10-08 09:09:18
類別是部門的孩子,我想把他們分成一個對象 – forgottofly 2014-10-08 11:23:27