对此感到困惑 &getcontext js/ts 以及如何解决它



所以,我有一个问题,我经常遇到未定义的错误,(在浏览器中),似乎无法弄清楚为什么/如何绕过它。从我收集到的是关键词"this"在js中是一个完全令人困惑的混乱;

我的问题是:

export class XY
{
property: boolean;
//other proprs
constructor()
{this.property = false;}
setproperty(e) //this is an onclick event
{
this.property = true;
//my problem is that this.property doesn't refer to class member variable "property"
}
}

即使我尝试像const boundGet = xy .bind.(xy),它仍然未定义且"不可达">

如果没有关键字"this",我该如何引用成员变量属性而不使其为const??

问题出在Devextreme的事件绑定上。如果你想覆盖他们的数据网格控件"编辑"事件,你必须像这样传递事件[onClick]="yourfunc"这显然不是标准的(event)="blabla"无论后台发生了什么,都会扰乱"this"的上下文。通过使用不同的事件来解决这个问题。

最新更新