typescript 获取错误:TypeError:无法读取undefined的属性(阅读“forEach”)

2vuwiymt  于 2023-05-01  发布在  TypeScript
关注(0)|答案(1)|浏览(445)

我在执行时收到Typescript错误错误错误如下所示:

TypeError: Cannot read properties of undefined (reading 'forEach')
at ScapprovalPaymentEventComponent.<anonymous> (http://localhost:50000/main.js?v=23.1.0+Build-17.02-1904:6102:33)
at step (http://localhost:50000/main.js?v=23.1.0+Build-17.02-1904:5940:23)
at Object.next (http://localhost:50000/main.js?v=23.1.0+Build-17.02-1904:5921:53)
at http://localhost:50000/main.js?v=23.1.0+Build-17.02-1904:5915:71
at new ZoneAwarePromise (http://localhost:50000/polyfills.js?v=23.1.0+Build-17.02-1904:8553:29)
at push../ClientApp/app/components/forms/scapproval-payment-event/scapproval-payment-event.component.ts.__awaiter (http://localhost:50000/main.js?v=23.1.0+Build-17.02-1904:5911:12)
at push../ClientApp/app/components/forms/scapproval-payment-event/scapproval-payment-event.component.ts.ScapprovalPaymentEventComponent.initializeControls (http://localhost:50000/main.js?v=23.1.0+Build-17.02-1904:6058:16)

这就是代码:

this.totalCount = response.total_rows;
this.bookmark = response.bookmark;
if (isPaginationCall && this.approvedForms && this.approvedForms.length > 0) {
    paymentForms.forEach(x => this.approvedForms.push(x));
} else {
    this.approvedForms = paymentForms;
}
this.onShowRecordChange();
setTimeout(() => {
    this.spinner.hide("MONITORPAYMENT");
}, 0);
jckbn6z7

jckbn6z71#

你可以对数组使用.forEach方法。当您尝试将.forEach方法与数组以外的其他数据结构一起使用时,会显示此错误。

相关问题