javascript - ReactJS - Handsontable - 确定更改

标签 javascript reactjs handsontable

我正在尝试获取我正在使用的 react-handsontable 组件中发生变化的值:

<HotTable root="hot"
                data={this.state.handsontableData}
                colHeaders={this.handsontableColumns}
                rowHeaders={true}
                width="1200"
                height="300"
                stretchH="all"
                colWidths={this.handsontableColWidths}
                onAfterChange={this.handleHOTChange(changes, source)} />

但是,onAfterChange={this.handleHOTChange(changes, source)} 抛出错误:

./src/MyComponent.jsx
  Line 73:  'changes' is not defined  no-undef
  Line 73:  'source' is not defined   no-undef

有人可以告诉我如何从事件中获取“更改”吗?

如果我只是使用 onAfterChange={this.handleHOTChange} 而不带参数,那么 handleHOTchanges 函数会在更改时被调用。但是,我如何确定发生了什么变化?

最佳答案

啊,修好了:

解决方案如下:

<HotTable root="hot"
                data={this.state.handsontableData}
                colHeaders={this.handsontableColumns}
                rowHeaders={true}
                width="1200"
                height="300"
                stretchH="all"
                colWidths={this.handsontableColWidths}
                onAfterChange={(changes, source) => this.handleHOTChange(changes, source)} />

关键是使用箭头函数语法:(changes, source) => this.handleHOTChange(changes, source)

下面是示例处理函数,用于打印在控制台中接收到的参数:

handleHOTChange(changes, source) {
     alert('changed!');
     console.log(changes);
   }

关于javascript - ReactJS - Handsontable - 确定更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46356053/

相关文章:

javascript - 将 2 条路线设置为同一组件的最佳方法是什么

javascript - 以不可变的方式更新数组中的一个对象

Meteor Handsontable 示例

javascript - react native : How to fix error with Button component during onPress?

javascript - 如何获取分配给 JSON 数组中相同键的重复值的计数 - JavaScript/NodeJS

javascript - React 在 setState 中访问超出范围的变量

reactjs - 在单独的文件中 react 路由器代码

reactjs - 如何使用axios获取redux中的api项?

arrays - 展平字典中的嵌套数组

handsontable - 如何编辑掌上电脑的标题文本?