js怎样将获取json转换为树形结构
1个回答
展开全部
比如这样一段json
{
"name":"1级菜单1",
"link":"###",
"isleaf": false,
"level": 0,
"children": [
{
"name":"2级菜单1",
"link":"###",
"isleaf": false,
"level": 1,
"children": [
{
"name":"3级菜单1",
"link":"###",
"isleaf": true,
"level": 2,
"children": null
},
{
"name":"3级菜单2",
"link":"###",
"isleaf": true,
"level": 2,
"children": null
}
]
},
{
"name":"2级菜单2",
"link":"###",
"isleaf": false,
"level": 1,
"children": [
{
"name":"3级菜单3",
"link":"###",
"isleaf": true,
"level": 2,
"children": null
}
]
}
]
}
我怎样把他转换成
<div>
<a href="###">一级菜单</a>
<ul>
<li>
<a>2级菜单1</a>
<ul>
<li><a href="###">3级菜单1</a></li>
<li><a href="###">3级菜单2</a></li>
</ul>
</li>
<li>
<a href="###">2级菜单2</a>
.......
</li>
</ul>
</div>
{
"name":"1级菜单1",
"link":"###",
"isleaf": false,
"level": 0,
"children": [
{
"name":"2级菜单1",
"link":"###",
"isleaf": false,
"level": 1,
"children": [
{
"name":"3级菜单1",
"link":"###",
"isleaf": true,
"level": 2,
"children": null
},
{
"name":"3级菜单2",
"link":"###",
"isleaf": true,
"level": 2,
"children": null
}
]
},
{
"name":"2级菜单2",
"link":"###",
"isleaf": false,
"level": 1,
"children": [
{
"name":"3级菜单3",
"link":"###",
"isleaf": true,
"level": 2,
"children": null
}
]
}
]
}
我怎样把他转换成
<div>
<a href="###">一级菜单</a>
<ul>
<li>
<a>2级菜单1</a>
<ul>
<li><a href="###">3级菜单1</a></li>
<li><a href="###">3级菜单2</a></li>
</ul>
</li>
<li>
<a href="###">2级菜单2</a>
.......
</li>
</ul>
</div>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询