报错,atmSecondMenu.vue?bcc9:231 Uncaught (in promise) TypeError: Cannot read property ‘length‘ of null

问题:
atmSecondMenu.vue?bcc9:231 Uncaught (in promise) TypeError: Cannot read property 'length' of null
at eval (atmSecondMenu.vue?bcc9:231)

原因:
(3) [{…}, {…}, {…}]0: {entryId: 11, entryName: "01", entryLevel: 1, parentEntryId: 0, entryType: 0, …}agency: "01"children: [{…}]control: "01"deployType: "01"description: "01"disableDate: "01"enableDate: "01"entryId: 11entryLevel: 1entryName: "01"entryType: 0externalName: "01"iconFile: "01"id: "01"name: "01"parentEntryId: 0pathType: "Folder"position: "01"reserved: nullstatus: "0"urlHost: "01"urlPort: "01"version: "01"visibility: "01"__proto__: Object1: {entryId: 12, entryName: "02", entryLevel: 1, parentEntryId: 0, entryType: 1, …}agency: "02"children: nullcontrol: "02"deployType: "02"description: "02"disableDate: "02"enableDate: "02"entryId: 12entryLevel: 1entryName: "02"entryType: 1externalName: "02"iconFile: "02"id: "02"name: "02"parentEntryId: 0pathType: "Folder"position: "02"reserved: nullstatus: "0"urlHost: "02"urlPort: "02"version: "02"visibility: "02"__proto__: Object2: {entryId: 15, entryName: "03", entryLevel: 1, parentEntryId: 0, entryType: 1, …}length: 3__proto__: Array(0)
atmSecondMenu.vue?bcc9:228 2222222222
atmSecondMenu.vue?bcc9:229 [{…}]0: {…}length: 1__proto__: Array(0)
atmSecondMenu.vue?bcc9:228 2222222222
atmSecondMenu.vue?bcc9:229 null

解决:
在for循环之前加非空判定:
if (res.data.data!=null){
  console.log(22222);
  console.log(res.data.data);
  for(var i=0;i<res.data.data.length;i++){
    if (res.data.data[i].children!=null){
      console.log(2222222222);
      console.log(res.data.data[i].children);
      for(var j=0;j<res.data.data[i].children.length;j++){
        if (res.data.data[i].children[j].parentEntryId==this.secondMenuPageInfo.entryId){
          me.tableData.push(res.data.data[i].children[j]);
        }
      }
    }
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值