微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

onChnge 传递以前的值,而不是当前值

如何解决onChnge 传递以前的值,而不是当前值

每当我输入时,console.log 只显示以前输入的值。例如。如果我输入 326 ,它只显示 32 。所以我知道我必须在 handleChange 中做一些修改。但我不知道该怎么做...

export default class create_po extends Component{
   constructor(props) {
      super(props);
      
   this.state = {
      rows: [{}]
    }
   };
    handleChange = idx => e => {
      const { name,value } = e.target;
      const rows = [...this.state.rows];
      rows[idx] = {  [name]: value,};


      this.setState({
         rows
      }),console.log(this.state.rows)
         };



render(){
    return (
            <table> 
                <thead>
                     <tr>
                       <th>Amount</th>
                     </tr>
                </thead>
                 <tbody>
                {this.state.rows.map((item,idx) => (
                 <tr>
                 <td><input type="text" name="quantity" value={this.state.rows[idx].quantity} 
                  onChange={this.handleChange(idx)}  className="form-control" />
                 </td>
                 </tr> )
                </tbody>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。