如图
将数据转为树形结构,并给第二级结构添加class类
buildtree(list, arr, parentId) {
list.forEach((item) => {
if (item.parentId === parentId) {
var child = {
key: item.id,
id: item.id,
value: item.id,
title: item.name,
scopedSlots: { title: 'title' },
children: [],
}
if(item.type=='station_type'){
child.class ="last_leaf" //给第二级添加class类
}
this.buildtree(list, child.children, item.id)
if (child.children.length === 0) {
delete child.children
child.isLast = true
}
arr.push(child)
}
})
},
<style lang="less" scoped>
/deep/ .last_leaf {
.ant-tree-child-tree{
display: flex !important;
flex-wrap: wrap;
.ant-tree-treenode-switcher-open{
width: 185px;
}
.ant-tree-treenode-switcher-close{
width: 185px;
}
}
}