gpt4 book ai didi

javascript - ReactJS - Handsontable - 确定更改

转载 作者:行者123 更新时间:2023-11-30 09:30:55 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com