reactjs - 如何在 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)} />
它没有按我的意愿工作。我希望你的帮助。
解决方案
您没有将第一个参数传递给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)} />
推荐阅读
- android - 我在为 appium 安装 Genymotion 时是否需要安装 VM 虚拟机
- python - 我如何获得一个隐藏在 OrderedDict 中的值
- python - 汇总三列,在不同条件下汇总,然后加入
- javascript - 按数组中第一个元素排序
- android - setTextAlignment() & setGravity() 不能动态工作
- java - 当我点击推送通知时,特定活动未打开(需要真正的帮助)
- java - isAbstract() 修饰符返回不正确的结果 - 为什么?
- amazon-web-services - 从 AWS API-Gateway 找出 lambda 名称
- swift - 如何快速删除 UIMenuController 项目?
- php - Laravel 关系:获取产品的评论和相关用户