一般多选的树形组件,使用getCheckedNodes()方法只能获取到本级的菜单id,只有在子菜单全部选中的情况下才会选中上级。但我们想要不全选中子级的情况下也要获取它的上级,甚至上上级等,怎么办呢?

需要改一下node_modules中的源码:文件路径为node_modules\element-ui\lib\element-ui.comment.js

搜索文中的TreeStore.prototype.getCheckedNodes方法,改为:

if ((child.checked || child.indeterminate) && (!leafOnly || leafOnly && child.isLeaf)) {
    checkedNodes.push(child.data)
}

 就ok啦!

在代码里仍然是this.$refs.tree.getCheckedNodes(),这样使用。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2021-07-27
  • 2022-02-21
  • 2021-06-03
猜你喜欢
  • 2021-11-30
  • 2021-07-29
  • 2022-12-23
  • 2021-10-01
  • 2022-03-10
  • 2022-12-23
相关资源
相似解决方案