我试图在tableInstance.forceUpdateGrid()
回调中调用Promise.then()
并且它抛出异常TypeError: Cannot read property 'Grid' of undefined
看下面的代码
_createClass(Table, [{
key: 'forceUpdateGrid',
value: function forceUpdateGrid() {
this.Grid.forceUpdate();
}
this
引用未定义...
我唯一能想到的是,在最初的BE api调用和Promise.then()
处理程序之间,有一个道具更改导致包含组件重新渲染,并且可能tableInstance
引用不再指向正确的实例?
有人可以帮忙吗?
(1)使用fat arrow functions
在函数内获取this
引用: -
_createClass(Table, [{
key: 'forceUpdateGrid',
value: forceUpdateGrid = () => {
this.Grid.forceUpdate();
}
(2)或者,
let thisRef = this;
_createClass(Table, [{
key: 'forceUpdateGrid',
value: function forceUpdateGrid() {
thisRef.Grid.forceUpdate();
}
我希望它有所帮助!