From 8d075c1a693adbb58da252776153fb43dc4e0f99 Mon Sep 17 00:00:00 2001 From: qqkj Date: Sat, 6 Mar 2021 18:06:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E7=B1=BB=E6=A0=91?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=87=BA=E6=9D=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/mdp/arc/category/CategoryTree.vue | 52 +++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/src/views/mdp/arc/category/CategoryTree.vue b/src/views/mdp/arc/category/CategoryTree.vue index 8f742c77..182adabf 100644 --- a/src/views/mdp/arc/category/CategoryTree.vue +++ b/src/views/mdp/arc/category/CategoryTree.vue @@ -3,7 +3,7 @@ { var tips=res.data.tips; if(tips.isOk==true){ - this.treeData=[res.data.data]; + this.treeData=res.data.data; console.log("this.treeData----"+JSON.stringify(this.treeData)); }else{ this.$message({ message: tips.msg, type: 'error'}); @@ -308,7 +312,49 @@ //return h('span',"@contextmenu.prevent='contextmenu('"+node.id+"')',"+node.label+"("+(data.children==null?0:data.children.length)+countMsg+")") ; } - } + }, + translateDataToTree(data2) { + var data=JSON.parse(JSON.stringify(data2)); + + let parents = data.filter(value =>{ + //如果我的上级为空,则我是最上级 + if(value.pid == 'undefined' || value.pid == null || value.pid == ''){ + return true; + + //如果我的上级不在列表中,我作为最上级 + }else if(data.some(i=>value.pid==i.id)){ + return false; + }else { + return true + } + + }) + let children = data.filter(value =>{ + if(data.some(i=>value.pid==i.id)){ + return true; + }else{ + return false; + } + }) + let translator = (parents, children) => { + parents.forEach((parent) => { + children.forEach((current, index) => { + if (current.pid === parent.id) { + let temp = JSON.parse(JSON.stringify(children)) + temp.splice(index, 1) + translator([current], temp) + typeof parent.children !== 'undefined' ? parent.children.push(current) : parent.children = [current] + } + } + ) + } + ) + } + + translator(parents, children) + + return parents + }, }, mounted() { this.nodeid=this.value;