【问题标题】:How to get data from table row click using Semantic's React Table Component如何使用 Semantic 的 React Table 组件从表行点击获取数据
【发布时间】:2017-09-14 16:13:43
【问题描述】:

我正在尝试从使用 React 的语义 UI 呈现的表中获取点击值。我使用不可变列表生成我的行,并且我想要一个可以访问唯一 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>
        )
      })
  }

【问题讨论】:

    标签: reactjs semantic-ui semantic-ui-react


    【解决方案1】:

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

      &lt;Table.Row key = {scen.get('id')} onClick={() =&gt; this.props.tableRowClickFunc(scen.get('id'))}&gt;

    【讨论】:

      【解决方案2】:

      这就是我如何让该行作为 react-router 链接工作:

      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>
      )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-05
        • 2022-01-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多