关于如何过滤treeData的children中的数据

//定义数据

const treeData= [
  {
    title: '客户基本信息',
    key: '1001',
    children: [
      {
        key: '10011',
        title: '客户',
        dataIndex: 'kh',
        width: 60,
      },
      {
        key: '10012',
        title: '销售员',
        dataIndex: 'xsy',
        width: 60,
      },
      {
        key: '10013',
        title: '联系人',
        dataIndex: 'lxr',
        width: 60,
      },
      {
        key: '10014',
        title: '来源',
        dataIndex: 'ly',
        width: 60,
      }
    ],
  },
  {
    title: '推荐信息',
    key: '1002',
    children: [
      {
        key: '10021',
        title: '存量情况',
        dataIndex: 'clqk',
        width: 60,
      },
      {
        key: '10022',
        title: '渗透情况',
        dataIndex: 'stqk',
        width: 60,
      },
      {
        key: '10023',
        title: '商机情况',
        dataIndex: 'sjqk',
        width: 60,
      },
    ],
  },
  {
    title: '产值盘点',
    key: '1003',
    children: [
      {
        key: '10031',
        title: '总产值',
        dataIndex: 'zcz',
        width: 60,
      },
      {
        key: '10032',
        title: '预计日期',
        dataIndex: 'yjrq',
        width: 60
      },
      {
        key: '10033',
        title: '预计方式',
        dataIndex: 'yjfs',
        width: 60
      },
    ],
  },
]

// 封装方法

export const filterData= (treeData = []) => {
     let columnsList = treeData .map(item => {
       if (item.children && item.children.length) {
         item.children = item.children.filter(todo => !todo.key != '10033')
       }
       return item
     })
     return columnsList
   }

// filterData(treeData) 即可

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Vue3使用Element UI的tree组件,可以通过以下步骤获取选数据及半选节点数据并将选数据组合成data格式的数据: 1. 在tree组件添加ref属性,命名为tree: ```html <el-tree ref="tree" :data="treeData" :props="treeProps" @check="handleCheck"></el-tree> ``` 2. 在data定义一个数组selectedData,用于存储选的节点数据: ```javascript data() { return { treeData: [/* 树形数据 */], treeProps: { /* 树形属性配置 */ }, selectedData: [] // 存储选的节点数据 } } ``` 3. 在@check事件获取选的节点数据: ```javascript methods: { // 当选节点发生变化时触发 handleCheck(checkedNodes, checkedNode) { // 遍历所有选节点 this.selectedData = checkedNodes.map(node => { const { id, label } = node.data // 如果节点半选,则需要将其子节点也加入到结果 if (node.indeterminate) { const children = node.childNodes.filter(child => child.checked) return { id, label, children: children.map(child => child.data.id) } } return { id, label } }) } } ``` 4. 将选数据组合成data格式的数据: ```javascript // 获取树形数据和选数据 const treeData = this.$refs.tree.getCheckedNodes() const selectedData = this.selectedData // 将选数据组合成data格式的数据 const data = treeData.map(node => { const { id, label } = node.data // 如果节点半选,则需要将其子节点也加入到结果 if (node.indeterminate) { const children = node.childNodes.filter(child => child.checked) return { id, label, children: children.map(child => child.data.id) } } // 如果节点被选,则直接加入到结果 if (node.checked) { return { id, label } } // 如果节点未被选,则不加入到结果 return null }).filter(node => node !== null) // 过滤掉未被选的节点 // 将选数据加入到结果 data.push(...selectedData) // 去重 const map = new Map() data.forEach(item => map.set(item.id, item)) const result = Array.from(map.values()) ``` 这样就可以获取到选数据及半选节点数据,并将其组合成data格式的数据了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值