4 回答
TA贡献1829条经验 获得超13个赞
TA贡献1779条经验 获得超6个赞
也可以递归的时候加入布尔,可以根据parent 是否为undefined,根节点肯定是undefined,然后再根据其他节点布尔搭配进行显示隐藏
title: '一级节点',
expanded: false,
children: [{
title: '二级节点',
expanded: false,
children: [{
title: '三级节点'
}, {
title: '三级节点'
}, {
title: '三级节点'
}]
}, {
title: '二级节点',
expanded: false,
children: [{
title: "<span style='color: red'>三级节点2-1</span>"
}, {
title: "<span style='color: red'>三级节点2-2</span>"
}]
}]
}]
recursion: function (val,arr1,$treeId,parent) {
// 递归
for (let i = 0; i < val.length; i++) {
arr1.push({ node: val[i], $treeId: $treeId, parent: parent })
if (val[i].children && val[i].children.length > 0) {
this.recursion(val[i].children, arr1, $treeId + 1, val[i])
}
}
return arr1
}
vue 页面 parent === undefined || parent.expanded === undefined || parent.expanded === true
添加回答
举报