elementUi中tree组件获取父节点的id

news/2024/7/10 0:38:54 标签: vue

在tree组件中用@current-change="getLeafKeys"事件

methods中
(b是tree组件获取的node)
getLeafKeys(a,b){
      var parentList = []
      function getParent (node) {
            // 判断当前节点是否有父节点,并且父节点上的data不能是数组
            if (node.parent && !Array.isArray(node.parent.data)) {
              // 将父节点上data的menuid存储在 `parentlist` 里
              node.parent.data instanceof Object && parentList.push(node.parent.data.id)
              // 递归调用 父节点上有父节点
              getParent(node.parent)
              // 当父节点上data是数组时点击对象为当前tree最高目录 并且parentList必须是0
            } else if (parentList.length === 0) {
              // 存储当前节点的id到parentList
              parentList.push(node.data.id)
            }
          }
          getParent(b)
          console.log(parentList)//获取所有父节点id
    }

http://www.niftyadmin.cn/n/1367736.html

相关文章

搜素模糊查询可以大小写

//leafname 查询输入的值 nodes循环的数据 path内部使用 function findPathByLeafId(leafname, nodes, path) {if (path undefined) {path []}for (var i 0; i < nodes.length; i) {var names nodes[i].name if (names.toLowerCase().includes(leafname) true) {path.…

jsplumb连线的数据

var g_MyJsPlumb null;funInitJSPlumb function() {g_MyJsPlumb jsPlumb.getInstance({Endpoint:["Dot", { radius: 7 }], // 端点形状ConnectionOverlays: [["Arrow", { width: 12, length: 12, location: 1 }]], // 连线样式 装饰属性 箭头Connecto…

点击空白页面隐藏弹窗

<p class"parameter" v-clickoutside"handleClose" click"processParameters">点击</p><script> const clickoutside {// 初始化指令bind(el, binding, vnode) {function documentHandler(e) {// 这里判断点击的元素是否是本…

正则将回车或换行转换成逗号

//将将回车后换行转换成逗号 String.replace(/\r|\n/g,,) //字符串将逗号转换成换行 String.replace(/[\,]/g,\n)

element ui中el-tree横向和竖向滚动条问题

.tree{overflow-y: hidden;overflow-x: scroll;width:100%;height: 700px;overflow: auto;}.el-tree {min-width: 100%;display:inline-block !important;}

复制json对象的按钮

var input document.createElement("input") // 直接构建input input.value JSON.stringify(this.contentJson) // 设置内容 document.body.appendChild(input) // 添加临时实例 input.select() document.execCommand(Copy) document.body.removeChild(inpu…

点击下载文件

downloadFile() {var content JSON.parse(sessionStorage.getItem(content))var ind content.filter(item > {return item.id this.offlineIds * 1})let uri data:text/csv;charsetutf-8,\ufeff encodeURIComponent(this.contentJson) //this.contentJson下载的内容//…

将josn对象转换成string并格式化

JSON.stringify(this.contentJson, null, \t)