"data": [
{
"id": 1,
"pId": 0,
"name": "一级1"
},
{
"id": 2,
"pId": 0,
"name": "一级2"
},
{
"id": 3,
"pId": 1,
"name": "二级1"
},
{
"id": 4,
"pId": 2,
"name": "二级2"
},
{
"id": 5,
"pId": 3,
"name": "三级1"
},
{
"id": 6,
"pId": 3,
"name": "三级2"
},
{
"id": 7,
"pId": 3,
"name": "三级3"
},
{
"id": 8,
"pId": 4,
"name": "三级4"
}
]
getTree(pId, arr) {
let children = []
for(let i = 0; i < arr.length; i++){
if(arr[i].pId == pId) {
arr[i].children = this.getTree(arr[i].id,arr)
children.push(arr[i])
}
}
return children
},