1
例如,我想解析以下的數組:解析扁平陣列成嵌套結構(樹)
var array1 = ["a.b.c.d", "a.e.f.g", "a.h", "a.i.j", "a.b.k"]
成:
var json1 = {
"node": "a",
"leaf": false,
"children": [{
"node": "b",
"leaf": false,
"children": [{
"node": "c",
"children": [{
"node": "d",
"leaf": true,
"children": []
}]
},
{
"node": "h",
"leaf": true,
"children": []
}
]
},
{
"node": "e",
"leaf": false,
"children": [{
"node": "f",
"leaf": true,
"children": []
}]
},
{
"node": "g",
"leaf": true,
"children": []
}
]
}
我認爲D3.JS提供這樣做的好方法,但我找不到一個好例子。
感謝您的幫助!
看一看https://stackoverflow.com/questions/44679971/create-nested-object-from-multiple-string-paths/44680094#44680094 –