js怎样将获取json转换为树形结构
答案:1 悬赏:10 手机版
解决时间 2021-04-22 20:45
- 提问者网友:泪痣哥哥
- 2021-04-22 12:25
js怎样将获取json转换为树形结构
最佳答案
- 五星知识达人网友:摆渡翁
- 2021-04-22 13:03
比如这样一段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>
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯