gpt4 book ai didi

javascript - react 类型错误: Cannot read property 'bind' of undefined

转载 作者:行者123 更新时间:2023-12-03 01:33:02 24 4
gpt4 key购买 nike

        <div className="questions" id="questions">
{Array(this.state.numQuestions).fill().map((number, questionIdx) => {
return (
<div>
<label>Question</label>
<input type="text" onChange={this.handleQuestionChange.bind(questionIdx)} />
</div>);
Array(4).fill().map((number, index) => {
return <input type="text" key={index} onChange={this.handleAnswerChange.bind(questionIdx)} />
})}
)
})}
</div>

我在 <input type="text" onChange={this.handleQuestionChange.bind(questionIdx)} /> 行中收到一个奇怪的错误

我不太清楚该错误意味着什么,更不用说如何修复它,这是错误信息:

TypeError: Cannot read property 'bind' of undefined

谢谢!

最佳答案

这意味着 this.handleQuestionChange 未定义,因此您无法对其调用 bind() (或其他任何内容)。

检查您的对象/函数并确保它存在。

关于javascript - react 类型错误: Cannot read property 'bind' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51194729/

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