Ver código fonte

树形结构更新

duxiangyu 3 anos atrás
pai
commit
b32501bae3

+ 1 - 0
src/components/project-manage/form/items/input.vue

@@ -142,6 +142,7 @@ export default {
       handler(info) {
         let pathArr = this.formItemObj.path.split(".");
         if (pathArr.length > 1 && info[pathArr[0]].hasOwnProperty(pathArr[1])) {
+          // console.log(this.filterInitValue(info[pathArr[0]][pathArr[1]]), 222);
           this.value = this.filterInitValue(info[pathArr[0]][pathArr[1]]);
         } else if (pathArr.length === 1) {
           this.value = this.filterInitValue(info[pathArr[0]]);

+ 14 - 16
src/components/project-manage/form/items/select.vue

@@ -66,24 +66,22 @@ export default {
       return tree;
     },
     listToTree(list) {
-      var map = {},
-        node,
-        tree = [],
-        i;
-      for (i = 0; i < list.length; i++) {
-        map[list[i].id] = list[i];
-        list[i].children = [];
-      }
-      for (i = 0; i < list.length; i += 1) {
-        node = list[i];
-        if (node.parentCode) {
-          // map[node.parentCode].children = [];
-          map[node.parentCode].children.push(node);
+      let map = {};
+      let result = [];
+      // 存映射,方便取值
+      list.forEach((el) => {
+        map[el.id] = el;
+      });
+      list.forEach((item) => {
+        const father = map[item.parentCode];
+        if (father) {
+          (father.children || (father.children = [])).push(item);
         } else {
-          tree.push(node);
+          result.push(item);
         }
-      }
-      return tree;
+      });
+
+      return result;
     },
   },
   watch: {