gpt4 book ai didi

javascript - 如何更新 forEach 函数中的变量?无法读取未定义的属性

转载 作者:行者123 更新时间:2023-11-30 20:40:29 24 4
gpt4 key购买 nike

<分区>

export class myclass implements OnInit {
private outagesList;
private outageArray;

constructor(private outages: OutagesService){}

ngOnInit(){
this.outages.getOutagesList().subscribe((data) => {
this.outagesList = data;
this.outagesList.forEach( function (arrayItem)
{
this.outageArray.push(arrayItem["title"]);
});
)
}

如果我尝试将数据推送到 outageArray,它会抛出 ERROR TypeError: Cannot read property 'outageArray' of undefined

我怎样才能避免这个错误?我需要将此 outageArray 值访问到 html。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com