我有分層的JSON,並希望轉換爲平坦的JSON沒有父子。分層json與父ID平坦
vm.str = [
{
"s_gid": 0,
"title": "scholastic Master List 2016",
"nodes": [
{
"Id": "1",
"templateId": "1",
"s_gid": "10",
"m_s_p_id": "1",
"subject_group_name": "xxxxxxx",
"parent_id": "1",
"sname": "",
"nodes": [
{
"Id": "2",
"templateId": "1",
"s_gid": "100",
"m_s_p_id": "0",
"subject_group_name": "abc",
"parent_id": "10",
"sname": "",
"nodes": [
{
"Id": "3",
"templateId": "1",
"s_gid": "1000",
"m_s_p_id": "0",
"subject_group_name": "efg",
"parent_id": "100",
"sname": ""
}
]
}
]
}
]
}
]
什麼轉換爲新vm.str2 = []平,在同級別無節點...子節點的所有節點..
謝謝。它正在工作,但我得到4 braket「[[[[」從開始 – fresher
確保你寫完全相同的代碼,再次檢查這部分'result.push(... flatten(o [e]))'也許你忘了' ......傳播運營商。 –
@fresher代替'...'擴展運算符,你也可以像這樣使用'concat()'https://jsfiddle.net/Lg0wyt9u/1217/ –