const root = document.getElementById('root');
function createTreeView(menu, currentNode) {
for (let i = 0; i < menu.length; i++) {
let li = document.createElement('li')
if (menu[i].children) {
let input = document.createElement('input')
input.type = 'checkbox'
let span = document.createElement('span')
let ul = document.createElement('ul')
li.append(input, span, ul)
currentNode.append(li)
span.textContent = menu[i].name
createTreeView(menu[i].children, ul)
}
else {
li.textContent = menu[i].name
currentNode.append(li)
}
}
}
createTreeView(menu, root);