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;
    },

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM