|
@@ -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) {
|