素材巴巴 > 程序开发 >

antdesign——Tree树形控件

程序开发 2023-09-13 06:49:44

在这里插入图片描述

需求

根据选中数据获取选中节点的keys集合

const checkedData = [{title: "0-0",key: "0-0",children: [{title: "0-0-0",key: "0-0-0",children: [{ title: "0-0-0-0", key: "0-0-0-0" }],},{title: "0-0-2",key: "0-0-2",},],},{title: "0-1",key: "0-1",children: [{ title: "0-1-0-0", key: "0-1-0-0" },{ title: "0-1-0-1", key: "0-1-0-1" },{ title: "0-1-0-2", key: "0-1-0-2" },],},{title: "0-2",key: "0-2",},
 ];mounted() {// 根据选中的树数组checkedData,获取默认选择的keys集合checkedKeysthis.checkedData.forEach((item) => {this.getDefaultKeys(item, this.checkedKeys);});},methods: {// 采用递归的方法获取选中的集合getDefaultKeys(node, arr) {if (!node.children) {return arr.push(node.key);}node.children.forEach((item) => {this.getDefaultKeys(item, arr);});},}
 

整个组件代码


 

标签:

素材巴巴 Copyright © 2013-2021 http://www.sucaibaba.com/. Some Rights Reserved. 备案号:备案中。