如何创建基于JavaScript对象的目录树表示
给定如下目录结构:如何创建基于JavaScript对象的目录树表示,javascript,object,directory,treeview,Javascript,Object,Directory,Treeview,给定如下目录结构: photos ├── summer │ └── june │ └── windsurf.jpg └── winter └── january ├── ski.png └── snowboard.jpg { "path": "photos", "name": "photos", "size": 600, "type": "directory", "children": [ {
photos
├── summer
│ └── june
│ └── windsurf.jpg
└── winter
└── january
├── ski.png
└── snowboard.jpg
{
"path": "photos",
"name": "photos",
"size": 600,
"type": "directory",
"children": [
{
"path": "photos/summer",
"name": "summer",
"size": 400,
"type": "directory",
"children": [
{
"path": "photos/summer/june",
"name": "june",
"size": 400,
"type": "directory",
"children": [
{
"path": "photos/summer/june/windsurf.jpg",
"name": "windsurf.jpg",
"size": 400,
"type": "file",
"extension": ".jpg"
}
]
}
]
},
{
"path": "photos/winter",
"name": "winter",
"size": 200,
"type": "directory",
"children": [
{
"path": "photos/winter/january",
"name": "january",
"size": 200,
"type": "directory",
"children": [
{
"path": "photos/winter/january/ski.png",
"name": "ski.png",
"size": 100,
"type": "file",
"extension": ".png"
},
{
"path": "photos/winter/january/snowboard.jpg",
"name": "snowboard.jpg",
"size": 100,
"type": "file",
"extension": ".jpg"
}
]
}
]
}
]
}
应该返回如下内容:
photos
├── summer
│ └── june
│ └── windsurf.jpg
└── winter
└── january
├── ski.png
└── snowboard.jpg
{
"path": "photos",
"name": "photos",
"size": 600,
"type": "directory",
"children": [
{
"path": "photos/summer",
"name": "summer",
"size": 400,
"type": "directory",
"children": [
{
"path": "photos/summer/june",
"name": "june",
"size": 400,
"type": "directory",
"children": [
{
"path": "photos/summer/june/windsurf.jpg",
"name": "windsurf.jpg",
"size": 400,
"type": "file",
"extension": ".jpg"
}
]
}
]
},
{
"path": "photos/winter",
"name": "winter",
"size": 200,
"type": "directory",
"children": [
{
"path": "photos/winter/january",
"name": "january",
"size": 200,
"type": "directory",
"children": [
{
"path": "photos/winter/january/ski.png",
"name": "ski.png",
"size": 100,
"type": "file",
"extension": ".png"
},
{
"path": "photos/winter/january/snowboard.jpg",
"name": "snowboard.jpg",
"size": 100,
"type": "file",
"extension": ".jpg"
}
]
}
]
}
]
}
你能展示一下你尝试过什么吗?我甚至不知道它是什么,从哪里开始?你是如何存储目录树的?我想是用javascript。。。我真的不知道你在说什么,我一直在搜索这个目录树结构。我的意思是,你的javascript的确切输入格式是什么?