el-tree和el-cascader结构生成

el-tree和el-cascader结构生成

   convertToTree(data, parentId) {
     const treeData = [];
     for (const item of data) {
       if (item.parentId == parentId) {
         const newNode = {
           label: item.deptLabel,
           value: item.deptId,
           children: this.convertToTree(data, item.deptId)
         };
         //去除最后一层
         if (newNode.children.length ==0) {
           delete newNode.children
         }
         treeData.push(newNode);
       }
     }
     console.log(treeData)
     return treeData;
   },

你可能感兴趣的:(Vue,javascript,开发语言,ecmascript)