Answer the question
In order to leave comments, you need to log in
How to set state onChange for position in []?
I have a table which is generated along with comment fields.
<Table responsive striped bordered condensed hover>
<thead>
<tr >
<th>#</th>
<th>Name</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
{
tabl.map( function(item,index)
{
return(
<tr>
<th>{1+index}</th>
<th>{item.name}</th>
<th>{item.number}</th>
<tr>
<th colSpan="3">
<Input type="textarea" />
</th>
</tr>
</tr> )}) }
</tbody>
</Table>
<Input type="textarea"
value={this.state.comments[index]}
onChange={ (event)=> this.state.comments.splice(index, 0, event.target.value ) }
/>
Answer the question
In order to leave comments, you need to log in
Like this
onChange={ (event)=> {
var comment = that.state.comments;
comment[index] = event.target.value;
that.setState({ comments: comment });
}}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question