el-tree根据id进行回显问题

949 阅读1分钟

el-tree根据id进行回显问题(以及怎么拿到父级(半选)id)

const checkedMenuIds = this.$refs.menuRef.getCheckedKeys()
const parentId = this.$refs.menuRef.getHalfCheckedKeys()

拿到id进行回显的时候出现各种问题

使用 check-strictly 虽然功能能实现, 但是还有一点小问题 最后通过 getNode 解决了, 直接上代码

this.$nextTick( () => {
const nodes = []
res.result.forEach((item) => {
  let node = this.$refs.menuRef.getNode(item) || {}
  if(node.isLeaf){
    nodes.push(item)
  }
})
this.$refs.menuRef.setCheckedKeys(nodes, true);
})

这样直接解决, 第一次在掘金上发布, 就当是自己的笔记