我有一个扁平的目录路径列表,我想将其转换为层次结构。
输入格式:
在我的输入中,我不能有任何父参数。我正在进行的fiddle在这里 - https://jsfiddle.net/ashwyn/Laamg14z/2/ 谢谢。
输入格式:
var paths = [
"A/B",
"A/B/C",
"A/B/C/D",
"A/B/C/E",
"F"
];
输出格式
[
{
"name": "A",
"children": [
{
"name": "B",
"children": [
{
"name": "C",
"children": [
{
"name": "D",
"children": []
},
{
"name": "E",
"children": []
}
]
}
]
}
]
},
{
"name": "F",
"children": []
}
]
在我的输入中,我不能有任何父参数。我正在进行的fiddle在这里 - https://jsfiddle.net/ashwyn/Laamg14z/2/ 谢谢。