与父母关系按字母顺序分类一棵树
我正在尝试创建一个编码环境,它有一个文件系统,用户可以在其中添加或删除文件,该文件系统是一个树结构,当用户更新该文件系统上的任何内容时,我试图按字母顺序对树进行排序。我尝试在互联网上查找但找不到太多。
[
{
"name": "src",
"id": "DfGfg_ckUK_YRM0Guwz-U",
"type": "dir",
"path": "/src",
"children": [
{
"name": "App.css",
"id": "VZ0DztZohJ5QNZA_MJEJj",
"type": "file",
"path": "/src/App.css",
},
{
"name": "style.css",
"id": "6djglLnepQ5VKpE02FfbJ",
"type": "file",
"path": "/src/style.css",
},
{
"name": "components",
"id": "LQtSXX8bXPRskbQGjBIsU",
"type": "dir",
"path": "/src/components",
"children": [
{
"name": "Clicker.js",
"id": "B-qo2rzjElEq_LdbflIik",
"type": "file",
"path": "/src/components/Clicker.js",
}
]
},
{
"name": "index.js",
"id": "A3aR70uZ-OA1dwLNon7RA",
"type": "file",
"path": "/src/index.js",
},
{
"name": "App.js",
"id": "_43kjHrcpFAvlvn0orNe6",
"type": "file",
"path": "/src/App.js",
}
]
},
{
"name": "public",
"id": "CaQSW19bFlIzdd5l0xKXX",
"type": "dir",
"path": "/public",
"children": [
{
"name": "index.html",
"id": "B1QcK9n8eRVVNF0N_jTeR",
"type": "file",
"path": "/public/index.html",
}
]
}
]
排序后的结构应如下所示。 type='dir' 首先出现(按字母顺序),然后是它的文件,这些文件也已排序。任何帮助将不胜感激。
[
{
"name": "public",
"id": "CaQSW19bFlIzdd5l0xKXX",
"type": "dir",
"path": "/public",
"children": [
{
"name": "index.html",
"id": "B1QcK9n8eRVVNF0N_jTeR",
"type": "file",
"path": "/public/index.html",
}
]
},
{
"name": "src",
"id": "DfGfg_ckUK_YRM0Guwz-U",
"type": "dir",
"path": "/src",
"children": [
{
"name": "components",
"id": "LQtSXX8bXPRskbQGjBIsU",
"type": "dir",
"path": "/src/components",
"children": [
{
"name": "Clicker.js",
"id": "B-qo2rzjElEq_LdbflIik",
"type": "file",
"path": "/src/components/Clicker.js",
}
]
},
{
"name": "App.css",
"id": "VZ0DztZohJ5QNZA_MJEJj",
"type": "file",
"path": "/src/App.css",
},
{
"name": "App.js",
"id": "_43kjHrcpFAvlvn0orNe6",
"type": "file",
"path": "/src/App.js",
},
{
"name": "index.js",
"id": "A3aR70uZ-OA1dwLNon7RA",
"type": "file",
"path": "/src/index.js",
},
{
"name": "style.css",
"id": "6djglLnepQ5VKpE02FfbJ",
"type": "file",
"path": "/src/style.css",
},
]
},
]
谢谢。
I am trying to make a coding environment it has a file system in which users could add or delete files, the file system is a tree structure and I am trying to sort the tree alphabetically when users update anything on that filesystem. I have tried looking on the internet but couldn't find much.
[
{
"name": "src",
"id": "DfGfg_ckUK_YRM0Guwz-U",
"type": "dir",
"path": "/src",
"children": [
{
"name": "App.css",
"id": "VZ0DztZohJ5QNZA_MJEJj",
"type": "file",
"path": "/src/App.css",
},
{
"name": "style.css",
"id": "6djglLnepQ5VKpE02FfbJ",
"type": "file",
"path": "/src/style.css",
},
{
"name": "components",
"id": "LQtSXX8bXPRskbQGjBIsU",
"type": "dir",
"path": "/src/components",
"children": [
{
"name": "Clicker.js",
"id": "B-qo2rzjElEq_LdbflIik",
"type": "file",
"path": "/src/components/Clicker.js",
}
]
},
{
"name": "index.js",
"id": "A3aR70uZ-OA1dwLNon7RA",
"type": "file",
"path": "/src/index.js",
},
{
"name": "App.js",
"id": "_43kjHrcpFAvlvn0orNe6",
"type": "file",
"path": "/src/App.js",
}
]
},
{
"name": "public",
"id": "CaQSW19bFlIzdd5l0xKXX",
"type": "dir",
"path": "/public",
"children": [
{
"name": "index.html",
"id": "B1QcK9n8eRVVNF0N_jTeR",
"type": "file",
"path": "/public/index.html",
}
]
}
]
The sorted structure should come out like the below.
The type='dir' comes first (alphabetically) and then its files which are also sorted. Any help would be appreciated.
[
{
"name": "public",
"id": "CaQSW19bFlIzdd5l0xKXX",
"type": "dir",
"path": "/public",
"children": [
{
"name": "index.html",
"id": "B1QcK9n8eRVVNF0N_jTeR",
"type": "file",
"path": "/public/index.html",
}
]
},
{
"name": "src",
"id": "DfGfg_ckUK_YRM0Guwz-U",
"type": "dir",
"path": "/src",
"children": [
{
"name": "components",
"id": "LQtSXX8bXPRskbQGjBIsU",
"type": "dir",
"path": "/src/components",
"children": [
{
"name": "Clicker.js",
"id": "B-qo2rzjElEq_LdbflIik",
"type": "file",
"path": "/src/components/Clicker.js",
}
]
},
{
"name": "App.css",
"id": "VZ0DztZohJ5QNZA_MJEJj",
"type": "file",
"path": "/src/App.css",
},
{
"name": "App.js",
"id": "_43kjHrcpFAvlvn0orNe6",
"type": "file",
"path": "/src/App.js",
},
{
"name": "index.js",
"id": "A3aR70uZ-OA1dwLNon7RA",
"type": "file",
"path": "/src/index.js",
},
{
"name": "style.css",
"id": "6djglLnepQ5VKpE02FfbJ",
"type": "file",
"path": "/src/style.css",
},
]
},
]
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要:
这是这样的外观:
You would need to:
Here is how that looks: