var render = function render (catgory) { if (!catgory) return null var ul = document.createElement('ul'); catgory.forEach(({name, list}) => { var li = document.createElement('li') var label = document.createElement('span'); label.innerText = name; li.appendChild(label); var sub = render(list); sub && li.appendChild(sub); ul.append(li); }) return ul }; document.body.innerHTML = ''; document.body.appendChild(render(catgory));
js 树形结构
最新推荐文章于 2022-11-21 16:31:29 发布