element tree 渲染部门、项目组织树

::vue html 部分代码

<el-tree

show-checkbox

ref="moduleTree"

:data="moduleList"

key="companyId"

node-key="companyId"

highlight-current

:default-expand-all="true"

node

default-expanded-keys

@check-change="handleCheckProjectChange"

:props="moduleProps"

>

</el-tree>

// 过滤要处理的参数;传给父组建

handleCheckProjectChange(data, node, self){

let f=this.$refs.moduleTree.getCheckedNodes();

this.node_data=f.map(item=>{

return {

grantType:item.type,

storeNo:item.companyId

}

})

this.$emit('sumbmitNode',this.node_data)

},



//接口获取详情数据后,更新到节点上。

this.$refs.moduleTree.setCheckedKeys(p);



处理项目组织树

传item.parentId-0,然后拿到主要key (item.code)

后端数据——》


this.moduleList= tranListToTreeData(res.data.data,'0')


export function tranListToTreeData(list, rootValue) {

  let arr = []

  list.forEach(item => {

    if (item.parentId === rootValue) {

      // 找到之后 就要去着item 下面有没有子节点

      const children = tranListToTreeData(list, item.code)

      if (children.length) {

        // 如果长度大于0 说明找到了子节点

        item.children = children

      }

      arr.push(item)  // 将内容加入到数组中

    }

  })

  return arr

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值