up
This commit is contained in:
parent
7b3f4550fd
commit
d85be5f17b
12 changed files with 47 additions and 93 deletions
|
@ -2,7 +2,7 @@ importance: 1
|
|||
|
||||
---
|
||||
|
||||
# Why "ааа" remains?
|
||||
# Why "aaa" remains?
|
||||
|
||||
Run the example. Why `table.remove()` does not delete the text `"aaa"`?
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
container.innerHTML = createTreeText(obj);
|
||||
}
|
||||
|
||||
function createTreeText(obj) { // отдельная рекурсивная функция
|
||||
function createTreeText(obj) { // standalone recursive function
|
||||
let li = '';
|
||||
for (let key in obj) {
|
||||
li += '<li>' + key + createTreeText(obj[key]) + '</li>';
|
||||
|
@ -38,7 +38,6 @@
|
|||
return ul || '';
|
||||
}
|
||||
|
||||
let container = document.getElementById('container');
|
||||
createTree(container, data);
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -43,12 +43,12 @@
|
|||
let lis = document.getElementsByTagName('li');
|
||||
|
||||
for (let li of lis) {
|
||||
// получить количество детей
|
||||
let childCount = li.getElementsByTagName('li').length;
|
||||
if (!childCount) continue;
|
||||
// get the count of all <li> below this <li>
|
||||
let descendantsCount = li.getElementsByTagName('li').length;
|
||||
if (!descendantsCount) continue;
|
||||
|
||||
// добавить кол-во детей к текстовому узлу
|
||||
li.firstChild.data += ' [' + childCount + ']';
|
||||
// add directly to the text node (append to the text)
|
||||
li.firstChild.data += ' [' + descendantsCount + ']';
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue