问题:
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]);
}
}
}
}
}