树形结构递归修改层级数据字段

 上代码

this.Positiondata  = get_tree(treeData); //treeData原数据  
						  function get_tree(treeData){
							for(var i = 0;i< treeData.length;i++){
								if(treeData[i].children.length){
									treeData[i].child =findChildren(treeData[i].children)  //原来的children改名为 child
					
								}else{
									treeData[i].child = []
									
								}
		                            treeData[i].Name = treeData[i].name  //原来的name  改名为Name
									treeData[i].parentid = treeData[i].parentId  //原来的parentId改名parentid  
							}
							return treeData
						}
						function findChildren(treeData){
							for(var i = 0;i< treeData.length;i++){
								if(treeData[i].children.length){
									treeData[i].child =findChildren(treeData[i].children)
								
								}else{
									treeData[i].child = []
									
								}
                                treeData[i].jGMC = treeData[i].name
								treeData[i].parentid = treeData[i].parentId
							}
							return treeData
						}

你可能感兴趣的:(vue,js,javascript,前端)