TypeError:无法读取Table.forceUpdateGrid中抛出的未定义属性“Grid”

问题描述 投票:0回答:1

我试图在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引用不再指向正确的实例?

有人可以帮忙吗?

react-virtualized
1个回答
0
投票

(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();
  }

我希望它有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.