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 (将#修改为@)