点击(此处)折叠或打开

  1. //格式化树将带node,children节点的json对象转化为符合elementui树控件所需要的数据格式
  2.     formatTreeData(data) {
  3.       let result = [];
  4.       if (data.length > 0) {
  5.         for (let i = 0; i < data.length; i++) {
  6.           let node = data[i].node; //每一个节点
  7.           let children = data[i].children; //对应的孩子节点
  8.           let mynode = {};
  9.           let keyArray = Object.keys(node);
  10.           for (var item of keyArray) {
  11.             mynode[item] = node[item]; //node对象的所有属性做成对象属性
  12.           }
  13.           if (children && children.length > 0) {
  14.             mynode["children"] = this.formatTreeData(children); //进行递归调用
  15.           } else {
  16.             mynode["children"] = [];
  17.           }

  18.           result.push(mynode);
  19.         }
  20.       }
  21.       return result;
  22.     }

11-27 19:18