我正在尝试获取我正在使用的 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/