var menuArray=[
{ id: 1, name: "", pid: 0 },
{ id: 2, name: "", pid: 1 },
{ id: 3, name: "UE", pid: 2 },
{ id: 4, name: "", pid: 2 },
{ id: 5, name: "", pid: 1 },
{ id: 6, name: "", pid: 5 },
{ id: 7, name: "Java", pid: 5 },
{ id: 8, name: "", pid: 1 },
{ id: 9, name: "1", pid: 8 },
{ id: 10, name: "2", pid: 8 }
];
convert the above data to the following data through operation
var data=[{
id:0,
name: "",
item:[{
id: 2,
name: "",
item: [
{
id:3,
name: "UE"
},
{
id:4,
name: ""
}
]
},
{
id: 5,
name: "",
item: [
{
id:6,
name: ""
},
{
id:7,
name: "Java"
}
]
},
{
id: 8,
name: "",
item: [
{
id:9,
name: "1"
},
{
id:10,
name: "2"
}
]
}
]
}]
Note: data depth is uncertain