vue elementui el-cascader级联选择器没子级时出现暂无数据问题

 

 原因时没有子级的时候后台返回了一个空数字  例如: children:[ ]

这时候需要递归将children为空的赋值为undefined

 

 

//获取系统分类管理列表
    getSystemTypeApi(){
      getSystemTypeApi({}).then((res)=>{
        if(res.data.code == 200){
          this.systemTypeList = this.getTreeData(res.data.data);
          // this.systemTypeList = res.data.data;
        }
      });
    },
    // 递归判断列表,把最后的children设为undefined
    getTreeData(data){
      for(var i=0;i<data.length>0;i++){
        if(data[i].children == null||data[i].children.length<=0){
          // children若为空数组,则将children设为undefined
          data[i].children = undefined;
        }else {
          // children若不为空数组,则继续 递归调用 本方法
          this.getTreeData(data[i].children);
        }
      }
      return data;
    },

 

posted @ 2021-04-20 17:22  遇你温柔如初  阅读(3244)  评论(0编辑  收藏  举报