Javascript 未捕获类型错误:this.handleSearchNext不是函数
我正在尝试覆盖handsontable的keyEvent。 代码运行,但将得到错误 “未捕获类型错误:this.handleSearchNext不是函数” 但它是一个定义的函数,所以我不确定为什么会出现这个错误Javascript 未捕获类型错误:this.handleSearchNext不是函数,javascript,reactjs,this,Javascript,Reactjs,This,我正在尝试覆盖handsontable的keyEvent。 代码运行,但将得到错误 “未捕获类型错误:this.handleSearchNext不是函数” 但它是一个定义的函数,所以我不确定为什么会出现这个错误 async componentWillReceiveProps(newProps) { this.hotTable.updateSettings({ afterDocumentKeyDown(e) { if (e.key === 'Enter') {
async componentWillReceiveProps(newProps) {
this.hotTable.updateSettings({
afterDocumentKeyDown(e) {
if (e.key === 'Enter') {
this.handleSearchNext(e)
e.stopPropagation()
console.log('Stopped propigation in table', e)
}
}
})
}
.
.
.
handleSearchNext = (e) => {...}
您必须将方法绑定到
this
:在构造函数中:this.handleSearchNext=this.handleSearchNext.bind(this)代码>可能重复@RandyCasburn,因为它是一个箭头函数,所以不需要特别绑定。不是()=>自动绑定函数吗?您必须将方法绑定到this
:在构造函数中:this.handleSearchNext=this.handleSearchNext.bind(this)代码>可能重复@RandyCasburn,因为它是一个箭头函数,所以不需要特别绑定。()=>是否自动绑定函数?