世界上最伟大的投资就是投资自己的教育

骑龙
id 13942
骑龙 10 hours 31 minutes 9 seconds 舵主 研究生 移动端用户
-
VSCODE 编辑器:rxreducer 快捷键可以生成 reducer 代码
-
特别喜欢这类总结性的文档👍
-
通过 React.createRef() 来绑定比较合适,可以避免一些不必要的隐藏错误。
1、constructor:constructor(props){ super(props); this.date = React.createRef(); this.comment = React.createRef(); this.amount = React.createRef(); this.state = { edit:false, } }
2、return 部分:
<tr> <td><input type="text" className="form-control" defaultValue={this.props.record.date} ref={this.date} /></td> <td><input type="text" className="form-control" defaultValue={this.props.record.comment} ref={this.comment} /></td> <td><input type="text" className="form-control" defaultValue={this.props.record.amount} ref={this.amount} /></td> <td> <button className="btn btn-info mr-1" onClick={this.handleUpdate}>更新</button> <button className="btn btn-danger" onClick={this.handleToggle}>取消</button> </td> </tr>
3、handleUpdate 函数:
handleUpdate = (event)=>{ event.preventDefault(); let data = { date:this.date.current.value, comment:this.comment.current.value, amount:Number.parseInt(this.amount.current.value,0) } console.log(data) // TODO:网络请求,更新数据 }
-
这样会多一次网络请求,当数据量比较大的时候不可取哦~
© 汕尾市求知科技有限公司 | Rails365 Gitlab | 知乎 | b 站 | csdn
粤公网安备 44152102000088号
| 粤ICP备19038915号