Single

JavaScript之无限极递归

最近在学JavaScript,记录下来的点点滴滴

var data=[
{
name:'AA',
child:[
{name:'a1',child:[{name:'a1-1'},{name:'a1-2'}]},//第一层
{name:'a2',child:[{name:'a2-1'},{name:'a2-2'}]},//第二层
{name:'a3',child:[{name:'a3-1'},{name:'a3-2'}]},//第三层
]
},
]
function createTree(data) {
var str="
<ul>
 	<li style="list-style-type: none;">
<ul>";</ul>
</li>
</ul>
<ul>
 	<li style="list-style-type: none;">
<ul>    for (var i=0; i&lt;data.lengvar;i++) {</ul>
</li>
</ul>
&nbsp;
<ul>
 	<li style="list-style-type: none;">
<ul>       str += '
 	<li>'+data[i].name
if (data[i].child) {
str += createTree(data[i].child)
}
str +='</li>
</ul>
</li>
</ul>
'
}
str +='

'
return str;
}
console.log(createTree(data))

 

暂无评论

发表评论