<div id='box'></div>
//下面是数据结构
let treeData = [
{
name:'小张',
age:18,
sex:'boy'
},
{
name:'人事部',
children:[
{
name:'小花',
age:20,
sex:'gril'
},
{
name:'小红',
age:19,
sex:'gril'
}
]
}
]
function treeList(datas){
let html = '<ul>';
datas.forEach(rs => {
html += '<li>'
html += `<span>${rs.name}</span>`
if(rs.children){
html += treeList(rs.children)
}
html += '</li>'
})
html += '</ul>'
return html
}
let box=document.getElementById('box');
box.innerHTML=treeList(treeData);