ฉันกำลังทำโปรเจ็กต์โดยใช้ Webix และ Python/Flask และฉันกำลังชนกำแพงอิฐด้วยการแสดงวิดเจ็ต treeview ปัญหาของฉันคือการสร้าง JSON ที่จำเป็นสำหรับวิดเจ็ตอย่างเหมาะสม ฉันกำลังพยายามสร้างโครงสร้างไดเร็กทอรีตามตัวอย่างที่กำหนด:
โครงสร้าง:
. ├── dirone │ └── file ├── dirthree │ ├── somedir │ │ └── anotherfile │ └── somefile ├── dirtwo └── somefile
ผลลัพธ์ที่ต้องการ:
[
{
"value": "dirone",
"path": "dirone",
"type": "folder",
"children": [
{
"value": "file",
"path": "dirone/file",
"type": "file"
}
]
},
{
"value": "dirtwo",
"path": "dirtwo",
"type": "folder",
"children": []
},
{
"value": "dirthree",
"path": "dirthree",
"type": "folder",
"children": [
{
"value": "somefile",
"path": "dirthree/somefile",
"type": "file"
},
{
"value": "somedire",
"path": "dirone/file",
"type": "folder",
"children": [
{
"value": "anotherfile",
"path": "dirthree/somedir/anotherfile",
"type": "file"
}
]
}
]
},
{
"value": "somefile",
"path": "somefile",
"type": "file"
}
]
ฉันต่อสู้กับสิ่งนี้มาสองชั่วโมงแล้วโดยพยายามหาวิธีการที่สามารถแสดงผลได้ มีใครมีวิธีสร้างโครงสร้างบ้างไหม? ความช่วยเหลือใด ๆ จะได้รับการชื่นชมอย่างมาก!