Basic cours support #44
1 changed files with 9 additions and 3 deletions
|
@ -2,8 +2,9 @@
|
|||
* Build the filetree
|
||||
* @param {HTMLElement} parent Root element of the filetree
|
||||
* @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");
|
||||
data.forEach((item) => {
|
||||
const li = document.createElement("li");
|
||||
|
@ -22,7 +23,11 @@ const buildFileTree = (parent, data) => {
|
|||
ul.appendChild(li);
|
||||
|
||||
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(
|
||||
fileTreeElement,
|
||||
JSON.parse(dataElement.getAttribute("data-json")).children
|
||||
JSON.parse(dataElement.getAttribute("data-json")).children,
|
||||
""
|
||||
);
|
||||
|
||||
dataElement.remove();
|
||||
|
|
Loading…
Reference in a new issue