有一个数组,数据为
var data=[
{id:1,parentId:null,name:'001'},
{id:2,parentId:1,name:'002'},
{id:3,parentId:4,name:'003'},
{id:4,parentId:5,name:'004'},
{id:5,parentId:1,name:'005'},
{id:6,parentId:1,name:'006'},]
请写一个函数,将以上数据结构转换为树形结构:
var treeNodes=[
{id:1,name:'001',children:[
{id:6:name:'006,'children:[]}]}]