如下图的需求:
1620456203(1).png
接口返回树结构数据如下:
[{
id: 1,
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
id: 2,
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1517 弄'
}, {
id: 3,
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1519 弄',
children: [{
id: 31,
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1519 弄'
}, {
id: 32,
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1519 弄'
}]
}, {
id: 4,
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄'
}]
仔细观察表格图,第二列name是id拼接name,于是:
handleTreeData(arr){
return arr.map(v=>{
var item={
id:v.id,
name:v.id+'-'+v.name,
date:v.date,
address:v.address
}
if(v.children){
item.children=this.handleTreeData(v.children)
}
return item
})
}
ok!
网友评论