我想将包含文件夹,json文件及其内容的文件夹结构映射到类似JSON对象的树视图中。我想问一下是否有人会向我提供一个函数,即loadFolder('/ a'),它将加载以下文件夹结构......
/ A
/a/file1.json
/a/file2.json
/a/b/file1.json
/ A / B / C
...会产生这个JSON对象:
{
path: "/a",
name: "a",
type: "folder",
subnodes: [
{
path: "/a/file1.json",
name: "file1.json",
type: "file",
content: {
// file content here
}
},
{
path: "/a/file2.json",
name: "file2.json",
type: "file",
content: {
// file content here
}
},
{
path: "/a/b",
name: "b",
type: "folder",
subnodes: [
{
path: "/a/b/file1.json",
name: "file1.json",
type: "file",
content: {
// file content here
}
},
{
path: "/a/b/c",
name: "c",
type: "folder",
subnodes: []
}
]
}
]
}