我有一个回调方法和局部变量的特殊问题:
export class Test {
model: Article;
onKeyEnter(value: string) {
this.model.maktx = "Test1";
//This is not working
this.find(value);
// Direct call is working
//this.readSuccessCallback(null, null);
}
find(nr) {
[..other stuff]
OData.read(request, this.readSuccessCallback, this.errorCallback);
}
readSuccessCallback(data, response) {
this.model.maktx = "Test2";
}
}
从onKeyEnter
直接调用readSuccessCallback
时,"Test2"
值设置正确
如果从OData.read
(SAP Kapsel 第三方)调用readSuccessCallback
方法,则会发生异常:
未捕获的 TypeError:无法设置 undefined 的属性“model”。
有谁知道发生了什么?我不知道OData.read
到底在做什么,但似乎我不会回到我要离开的地方?
2 回答
试试这个:
在我看来,你的
readSuccessCallback
被调用,但this
已成为undefined
。当您在严格模式下工作时可能就是这种情况(我相信这是从 1.8 开始的默认模式)。我不能在这里测试,但定义你的回调如下:
这应该导致
this
指向您的实际实例。