guanchunjie %!s(int64=3) %!d(string=hai) anos
pai
achega
370d63c1a5
Modificáronse 2 ficheiros con 19 adicións e 15 borrados
  1. 1 1
      package.json
  2. 18 14
      src/components/inputModules/common/TreeView.vue

+ 1 - 1
package.json

@@ -17,7 +17,6 @@
     "@tinymce/tinymce-vue": "^3.2.8",
     "awe-dnd": "^0.3.4",
     "axios": "0.18.1",
-    "book-ui": "file:../GCLS-Book-question-ui/book-ui-0.1.18.tgz",
     "cnchar": "^3.0.1",
     "cnchar-all": "^3.0.1",
     "cnchar-order": "^3.0.1",
@@ -56,6 +55,7 @@
     "babel-eslint": "10.1.0",
     "babel-jest": "23.6.0",
     "babel-plugin-dynamic-import-node": "2.3.3",
+    "book-ui": "file:../GCLS-Book-question-ui/book-ui-0.1.19.tgz",
     "chalk": "2.4.2",
     "compression-webpack-plugin": "^6.1.1",
     "connect": "3.6.6",

+ 18 - 14
src/components/inputModules/common/TreeView.vue

@@ -122,6 +122,7 @@ export default {
     async currentTreeID(newval, oldval) {
       if (newval) {
         this.activeIndex = newval;
+        this.pidList = [];
         await this.unfoldData(this.activeIndex, this.treeData);
         await this.unfoldFather(this.treeData);
       }
@@ -130,28 +131,31 @@ export default {
   methods: {
     // 递归找到当前节点的所有父节点
     unfoldData(activeIndex, data, index, child) {
-      data.forEach((item, i) => {
-        if (item.id == activeIndex) {
-          this.pidList.push(item.pid);
+      for (let i = 0; i < data.length; i++) {
+        if (data[i].id == activeIndex) {
+          this.pidList.push(data[i].pid);
           if (Object.prototype.toString.call(index).indexOf("Number") != -1) {
             this.pidList.push(child.pid);
           }
-        } else if (item.children) {
-          this.unfoldData(activeIndex, item.children, i, item);
+          // return false
+        } else if (data[i].children) {
+          this.unfoldData(activeIndex, data[i].children, i, data[i]);
         }
-      });
+      }
     },
     // 展示父节点
     unfoldFather(data) {
-      data.forEach((item, i) => {
-        this.pidList.forEach((p) => {
-          if (item.id == p) {
-            item.$folded = false;
-          } else if (item.children) {
-            this.unfoldFather(item.children);
+      for (let i = 0; i < data.length; i++) {
+        if (this.pidList.indexOf(data[i].id) > -1) {
+          data[i].$folded = false;
+          if (data[i].children) {
+            this.unfoldFather(data[i].children);
           }
-        });
-      });
+          // return false
+        } else if (data[i].children) {
+          this.unfoldFather(data[i].children);
+        }
+      }
     },
     foldAll() {
       if (this.$refs.tree !== undefined) {