这是Table组件
{this.props.tableData.map((item, index) => {
return (
<tr key={index}>
<td>{item.id}</td>
<td>{item.name}</td>
<td>{item.price}</td>
<td onClick={this.props.handleClick}>修改</td>
</tr>)
})}
这是调用Table组件的父组件
<TableCom title={['id', 'name', 'price','操作']}
tableData={this.props.reduxTableList}
handleClick={this.props.changeTable}>
</TableCom>
const mapDispatch = (dispatch) => {
return {
changeTable(){
dispatch(reduxTableState())
}
}
}
这是store的reducer
export default (state = defaultState, action) => {
if (action.type === 'changeTable') {
console.log(666)
return newState
}
我想改变store里table的state的值,需要在store里知道点击的是循环出的哪个,所以需要知道index<td onClick={this.props.handleClick(index)}>修改</td>
这样是不行的
<td onClick={this.props.handleClick.bind(this,index)}>修改</td>
<td onClick={()=>this.props.handleClick(index)}>修改</td>