点击(此处)折叠或打开
- //格式化树将带node,children节点的json对象转化为符合elementui树控件所需要的数据格式
- formatTreeData(data) {
- let result = [];
- if (data.length > 0) {
- for (let i = 0; i < data.length; i++) {
- let node = data[i].node; //每一个节点
- let children = data[i].children; //对应的孩子节点
- let mynode = {};
- let keyArray = Object.keys(node);
- for (var item of keyArray) {
- mynode[item] = node[item]; //node对象的所有属性做成对象属性
- }
- if (children && children.length > 0) {
- mynode["children"] = this.formatTreeData(children); //进行递归调用
- } else {
- mynode["children"] = [];
- }
- result.push(mynode);
- }
- }
- return result;
- }