小编典典

React-router:用作可点击的数据表行

reactjs

我是使用ReactJS和react-router的新手。我想要一个可点击的表格行以及类似以下设置的内容:

<Link to=“#”>
<tr>
    <td>{this.props.whatever1}</td>
    <td>{this.props.whatever2}</td>
    <td>{this.props.whatever3}</td>
</tr>
</Link>

但我知道您不能<a><tbody><tr>标签之间放置标签。我还能怎么做呢?

PS:如果可能的话,我宁愿不要使用jQuery。


阅读 228

收藏
2020-07-22

共1个答案

小编典典

您为什么不只使用onClick?

var ReactTable = React.createClass({
  handleClick: function(e) {
    this.router.transitionTo('index');
  },
  render: function() {
    return(
      <div>
        <table>
          <thead>
            <tr>
              <th>Name</th>
              <th>Age</th>
              <th>Full Detail</th>
            </tr>
          </thead>
            <tbody>
              <tr onClick={this.handleClick.bind(this)}>
                <td>{user.name}</td>
                <td>{user.age}</td>
                <td>{details}</td>
              </tr>
            </tbody>
        </table>
      </div>
    );
  }
});
2020-07-22