如题,数据格式是这样的:
datas = [
["root", "根节点", "root", None],
["node1", "一级节点1", "root", "root"],
["node2", "一级节点2", "root", "root"],
["node11", "二级节点11", "root", "node1"],
["node12", "二级节点12", "root", "node1"],
["node21", "二级节点21", "root", "node2"],
["node22", "二级节点22", "root", "node2"],
]
每条数据中的四个数据分别是 当前节点名称,节点描述(指代一些需要的节点属性),源节点(即最顶层节点),父节点(当前节点上一层节点)。
如何用非递归方式,比如循环,输出其树形结构啊:如这样的
{categoryList:[{
name:'水果',
parentId:'0',
id:'10',
isLeafe:'0',
children:[{
name:'香蕉',
parentId:'10',
id:'1010',
isLeafe:'1'
},{
name:'菠萝',
parentId:'10',
id:'1020',
isLeafe:'1'
}]
},{
name:'甜品',
parentId:'0',
id:'20',
isLeafe:'0'
},{
name:'文具',
parentId:'0',
id:'30',
isLeafe:'0'
},
]}
--
FROM 221.221.172.*