tree显示与点击

表结构

 `id` varchar(32)  'id',
  `house_name` varchar(50) '名称',
  `pid` varchar(32) '父级节点id',
  `path` varchar(8000) '完整路径',
  `path_name` varchar(4900)  '完整路径名称',
  `sort` int '排序',

前台展示函数

控件需要设置的地方
:props="defaultProps"

 defaultProps: {
   children: 'children',
   label: 'houseName'
 }

赋值调用

this.treeDeptData = this.toTree(this.treeBaseData, 0, "id", "houseName", "pid");

    /**
     * 更改为toTree(数据,第一层的pid值,id名,label名,pid名)
     *
     * 例:toTree(data,0,menuId,menuName,menuPid)
     */
    toTree(data, id, idName, labelName, pidName) {
      var result = [],
        temp;
      for (var i in data) {
        data[i].id = data[i][idName];
        data[i].label = data[i][labelName];
        if (data[i][pidName] == id) {
          result.push(data[i]);
          temp = this.toTree(data, data[i][idName], idName, labelName, pidName);
          if (temp.length > 0) {
            data[i].children = temp;
          }
        }
      }
      return result;
    },

点击取值,取树形递归

clickTree(data) {
  console.log('data.id=')
  console.log(data.id)
	  
		let nodeChild = "";
      function getIds(obj) {
        let ids = [];
        if (obj.children && obj.children.length > 0) {
          for (let i in obj.children) {
            ids.push.apply(ids, getIds(obj.children[i]));
          }
        }
        ids.push(obj.id);
        return ids;
      }

      if (this.treeDeptData[0].id == data.id) {
        nodeChild = "";
      } else {
        nodeChild = getIds(data).join();
      }

      console.log(nodeChild)
}

后台模糊查询

AND FIND_IN_SET(a.organi_id,'${query.nodeChild}')
posted @ 2023-03-15 10:54  寒冷的雨呢  阅读(16)  评论(0编辑  收藏  举报