The problem of getting the value after adding the input box dynamically to react

problem description


after iterating through the input box, I want to get the value of the array input box
the data structure is as follows: addItemList: [{deparment:"",types:"",money:""}]. When I join the input change event, I cannot enter the value in the input box, nor can I print the correct value

.

the environmental background of the problems and what methods you have tried

onInputchange= (fileds) = > (e) = > {
this.setState ({[fileds]: e.target.value});

}

related codes

addItemList.map((item,index)=><div key={index}>
                              <span>:</span><Input className={s.inW} value={item.deparment} onChange={this.onInputchange(item)}></Input>
                              <span>:</span><Input className={s.inW} value={item.types} onChange={this.onInputchange(item)}></Input>
                             <span>:</span><Input className={s.inW2} value={item.money} onChange={this.onInputchange(item)}></Input>
                            <span onClick={()=>{this.deleteItem(index)}}></span>
                            </div>

expect to get the value of input array. If you have any answers, thank you very much.

May.15,2022


:addItemList:[{deparment:'',types:'',money:''}]

render:

addItemList.map((item,index)=><div key={index}>
                              <span>:</span><Input className={s.inW} value={item.deparment} onChange={this.onInputchange('deparment',index)}></Input>
                            <span>:</span><Input className={s.inW} value={item.types} onChange={this.onInputchange('types',index)}></Input>
                          <span>:</span><Input className={s.inW2} value={item.money} onChange={this.onInputchange('money',index)}></Input>
                          <span onClick={()=>{this.deleteItem(index)}}></span>
                            </div>)

method: `onInputchange= (types,index) = > (e) = > {
let arr = this.state.addItemList;
arrindex = e.target.value
this.setState ({addItemList: [... arr]});
}

- Note that this.setState ({addItemList:arr}) cannot be used to update data directly; otherwise, the view will not be updated * *

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e3be96-4466b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e3be96-4466b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?