递归数据如何在页面上进行展示?
需求:如果有children数组,就递归一层,在渲染层应该怎么写这个逻辑
实现效果:
返回数据格式:
[
{
name: "test1",
value:0,
children:[
{
name:"1-1",
value:1,
children:[
{
name:"1-1-1",
value:4
}
]
},
{
name:"1-2",
value:2
},
{
name:"1-3",
value:3
}
]
},
{
name: "test2",
value:5,
children:[
{
name:"2-1",
value:6,
children:[
{
name:"2-1-1",
value:9
}
]
},
{
name:"2-2",
value:7
},
{
name:"2-3",
value:8
}
]
}
]
...
代码:
<el-collapse v-model="activeNames">
<div v-for="item in typeList" :key="item.id">
<el-collapse-item :title="item.name" :name="item.id">
<el-checkbox v-model="selectAll[item.name]" @change="handleSelectAll(item)">全选</el-checkbox>
<el-checkbox-group v-model="queryParams.device_sub_type" @change="handleSearch(item)">
<el-checkbox style="display: block;" v-for="obj in item.children" :key="obj.id" :label="obj.code">
{{ obj.name }}
</el-checkbox>
</el-checkbox-group>
</el-collapse-item>
</div>
</el-collapse>