<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Domtree</title>
</head>
<body>
<script>
var nodes=[
{id:2,text:"爷爷",parentId:0},
{id:4,text:"父亲",parentId:2},
{id:12,text:"叔叔",parentId:2},
{id:10,text:"我",parentId:4},
{id:8,text:"弟弟",parentId:4},
]
function Dom(nodes){
var obj={}
for(var i=0;i<nodes.length;i++)
{//console.log(typeof obj[nodes.parentId]);
if(!obj[nodes[i].parentId]){obj[nodes[i].parentId]=[]}
obj[nodes[i].parentId].push(nodes[i])
delete nodes
转化Json数组成树状图 自己的一些小见解
最新推荐文章于 2024-07-16 16:19:17 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)