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