This commit is contained in:
parent
b3cdcff067
commit
a9f48a79a4
1 changed files with 9 additions and 3 deletions
|
@ -2,8 +2,9 @@
|
||||||
* Build the filetree
|
* Build the filetree
|
||||||
* @param {HTMLElement} parent Root element of the filetree
|
* @param {HTMLElement} parent Root element of the filetree
|
||||||
* @param {{name: string, is_dir: boolean, children: any[]}} data FileNode
|
* @param {{name: string, is_dir: boolean, children: any[]}} data FileNode
|
||||||
|
* @param {string} location Current location, used for links creation
|
||||||
*/
|
*/
|
||||||
const buildFileTree = (parent, data) => {
|
const buildFileTree = (parent, data, location) => {
|
||||||
const ul = document.createElement("ul");
|
const ul = document.createElement("ul");
|
||||||
data.forEach((item) => {
|
data.forEach((item) => {
|
||||||
const li = document.createElement("li");
|
const li = document.createElement("li");
|
||||||
|
@ -22,7 +23,11 @@ const buildFileTree = (parent, data) => {
|
||||||
ul.appendChild(li);
|
ul.appendChild(li);
|
||||||
|
|
||||||
if (item.children && item.children.length > 0) {
|
if (item.children && item.children.length > 0) {
|
||||||
buildFileTree(li, item.children);
|
buildFileTree(
|
||||||
|
li,
|
||||||
|
item.children,
|
||||||
|
item.is_dir ? location + `${item.name}/` : location
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -35,7 +40,8 @@ window.addEventListener("load", () => {
|
||||||
|
|
||||||
buildFileTree(
|
buildFileTree(
|
||||||
fileTreeElement,
|
fileTreeElement,
|
||||||
JSON.parse(dataElement.getAttribute("data-json")).children
|
JSON.parse(dataElement.getAttribute("data-json")).children,
|
||||||
|
""
|
||||||
);
|
);
|
||||||
|
|
||||||
dataElement.remove();
|
dataElement.remove();
|
||||||
|
|
Loading…
Reference in a new issue