提问人:Levente 提问时间:8/10/2021 最后编辑:Levente 更新时间:8/10/2021 访问量:29
对此感到困惑 & getcontext js/ts 以及如何解决它
Confused about this & getcontext js/ts and how to get around it
问:
所以,我有一个问题,我经常遇到未被发现的错误,(在浏览器中),似乎无法弄清楚为什么/如何解决它。据我所知,关键字“this”在 js 中是一个完全令人困惑的混乱,在 ts 中也是如此。
这是我的problme:
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”,我应该如何在不使其常量的情况下引用成员变量属性?
答:
0赞
Levente
8/10/2021
#1
因此,事实证明,问题出在Devextreme的事件绑定上。 如果你想覆盖他们的数据网格控件 “edit” buttons 事件,你必须像这样传递事件 [onClick]=“yourfunc” 现在这显然不是标准的 (event)=“blabla”。 无论在后台发生什么,都会扰乱“this”的上下文。 通过使用不同的事件来解决问题。
评论
constructor() { this.property = false; }