首页 > 解决方案 > 如何在 React 中传递参数和 Input 的目标?

问题描述

我想同时传递参数和 Input 的目标。

handleChange (e, a) => {
 this.setState({
  price: e.target.value
 });
 this.callback(e.target.value, a);
}
...
<input type = 'text' value = {this.state.price} onChange = {(e) => handleChange(a)} />

它没有按我的意愿工作。我希望你的帮助。

标签: reactjs

解决方案


您没有将第一个参数传递给handleChange函数,请尝试:onChange = {(e) => handleChange(e, a)}

或者你可以这样做:

handleChange = (a) => event => {
 this.setState({
  price: event.target.value
 });
 this.callback(event.target.value, a);
}
...
<input type = 'text' value = {this.state.price} onChange = {handleChange(a)} />

推荐阅读