react map出的组件点击事件如何传index到store里

这是Table组件
{this.props.tableData.map((item,index)=>{
return(
{item.id}
{item.name}
{item.price}
修改
)
})}
这是调用Table组件的父组件
tableData={this.props.reduxTableList}
handleClick={this.props.changeTable}>
constmapDispatch=(dispatch)=>{
return{
changeTable(){
dispatch(reduxTableState())
}
}
}
这是store的reducer
exportdefault(state=defaultState,action)=>{
if(action.type==='changeTable'){
console.log(666)
returnnewState
}
我想改变store里table的state的值,需要在store里知道点击的是循环出的哪个,所以需要知道index修改这样是不行的
阿晨1998
浏览 812回答 2
2回答

白猪掌柜的

修改this.props.handleClick(index)}>修改constmapDispatch=(dispatch)=>{return{changeTable(index){console.log(index)dispatch(reduxTableState())}}}

holdtom

接上个答案,exportconstreduxTableState=(index)=>{return{type:constants.TABLE_STORE,index}}到store里就可以在action里取到index了
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript