如何使用语义的 React Table 组件从 table 行点击获取数据

How to get data from table row click using Semantic's React Table Component

我试图从我使用语义 UI 和 React 渲染的 table 中获取点击值。我使用 immutable 列表生成我的行,我想要一个可以访问唯一 id 值的 onclick。当我记录我在回调中提取值的尝试时,我得到:

'bff3a3e9-489e-0e19-c27b-84c10db2432b' 包裹在 td 标签中

相关代码:

  handleRowClick = (scen) => {
    console.log(Object.keys(scen.target));
    console.log(scen.target.);
  }

  mapScenarios = () => {
      return ((scen, i) => {
        return(
          <Table.Row key = {scen.get('id')} onClick = {this.handleRowClick}>
            <Table.Cell
              children={scen.get('id') || '(No ID)'}
            />
            <Table.Cell
              children={scen.get('name') || '(No Name)'}
            />
            <Table.Cell
              children={scen.get('actions').size === 0 ? 'none' : `${scen.get('actions').size} action(s)`}
            />
          </Table.Row>
        )
      })
  }

使用语义ui进行反应,行点击没有很好地实现。在行单击上,您实际上从该行获得了 CELL 的值,这不是我想要的,但我认为它有效,因为我单击的是包含 Id 的单元格。这是解决方法。

  <Table.Row key = {scen.get('id')} onClick={() => this.props.tableRowClickFunc(scen.get('id'))}>

这就是我如何让该行作为反应路由器工作的方式link:

const RowClickable = React.forwardRef((props, ref) => (
    <Table.Row ref={ref} onClick={props.navigate}>{props.children}</Table.Row>
))

const RowItem = ({id, name}) => (
    <Link to={`/item/${id}/`} component={RowClickable}>
        <Table.Cell>
            <Header as="h4">{name}</Header>
        </Table.Cell>
    </Link>
)