React jsx 怎么在回调中增加参数

用的 antd 的组件库
写了一个 select,这里的 onChange 只能拿到 value

function StatusCombo(props) {
     return   <Select onChange={props.onChangeStatus} }>  </Select>
}

然后写 columns,在 render 中把上边的 StatusCombo 渲染上去, 这里想给 onChangeStatus 再加上 record.key,因为 后面要用

createColumns() {
    return[{
        title: 'status',
        dataIndex: 'status',
        render: (text, record) => <StatusCombo onChangeStatus={this.onChangeStatus} ></StatusCombo>
      }]
}

最后处理需要 key 和变化的 status,因为 dispath action 时候需要这两个参数

onChangeStatus(key, status) {
   
  }

我应该怎样才能既获得改变的 status 还能获得当前的 key 呢

阅读 2.7k
1 个回答

方法1

<button onClick={(ev, arg1, arg2,……) => {this.handleClick(ev, arg1, arg2,……)}}/> 

handleClick(ev, arg1, arg,……) {
    //code
}

方法2

this.handleclick.bind(this,要传的参数)
// 调用
handleclick(要传的参数,event){
}

方法3

<button onClick={this.handleClick.bind(this, props0, props1, ...}></button>

handleClick(porps0, props1, ..., event) {
    // your code here
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题