use document fragment
This commit is contained in:
parent
47e386222f
commit
52e3674140
1 changed files with 6 additions and 3 deletions
|
@ -5,7 +5,10 @@
|
||||||
* @param {string} location Current location, used for links creation
|
* @param {string} location Current location, used for links creation
|
||||||
*/
|
*/
|
||||||
const buildFileTree = (parent, data, location) => {
|
const buildFileTree = (parent, data, location) => {
|
||||||
|
const fragment = document.createDocumentFragment();
|
||||||
const ul = document.createElement("ul");
|
const ul = document.createElement("ul");
|
||||||
|
fragment.appendChild(ul);
|
||||||
|
|
||||||
data.forEach((item) => {
|
data.forEach((item) => {
|
||||||
const li = document.createElement("li");
|
const li = document.createElement("li");
|
||||||
li.classList.add(item.is_dir ? "directory" : "file");
|
li.classList.add(item.is_dir ? "directory" : "file");
|
||||||
|
@ -32,16 +35,16 @@ const buildFileTree = (parent, data, location) => {
|
||||||
|
|
||||||
ul.appendChild(li);
|
ul.appendChild(li);
|
||||||
|
|
||||||
if (item.children && item.children.length > 0) {
|
if (item.children?.length) {
|
||||||
buildFileTree(
|
buildFileTree(
|
||||||
li,
|
li,
|
||||||
item.children,
|
item.children,
|
||||||
item.is_dir ? location + `${item.name}/` : location
|
item.is_dir ? `${location}${item.name}/` : location
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
parent.appendChild(ul);
|
parent.appendChild(fragment);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue