You need to enable JavaScript to run this app. Material Table点击按钮获取行数据(非行选中模式)实现方法咨询
优惠活动
大模型
产品
解决方案
定价
更多

Material Table点击按钮获取行数据(非行选中模式)实现方法咨询

解决方法

你只需要在绑定删除按钮点击事件时,将遍历过程中当前行的row对象作为参数手动传入处理函数即可,具体修改如下:

  1. 修改删除按钮的onClick绑定逻辑,用箭头函数包裹调用,同时传入事件对象和当前行数据:
<IconButton onClick={(e) => this.onDeleteButtonClick(e, row)}>
    <DeleteIcon style={{ color: 'red' }}/>
</IconButton>
  1. 之后你在onDeleteButtonClick方法里就能直接获取到对应行的完整数据:
onDeleteButtonClick = (event, row) => {
    console.log('onDeleteButton Click!');
    console.log('当前点击行数据', row); // 这里就能拿到你需要的行信息
}

如果你习惯用bind传参,需要注意参数顺序:bind传入的自定义参数会排在原生事件对象前面,对应的写法为:

<IconButton onClick={this.onDeleteButtonClick.bind(this, row)}>

对应的处理函数参数顺序需要调整为:

onDeleteButtonClick = (row, event) => {
  // 业务逻辑代码
}

内容的提问来源于stack exchange,提问作者IonicMan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.08 21:21:01