6

考虑这个 JSX 结构:

<table>
  <tbody>
    <tr>
      <td>{this.props.firstName}</td>
      <td>{this.props.lastName}</td>
    </tr>
  </tbody>  
</table>

当其中一个道具更新时,我想使用CSSTransitionGroup设置 td 的背景颜色,如下所示:

<table>
  <tbody>
    <tr>
      <ReactCSSTransitionGroup transitionName="example">
        <td key={this.props.firstName}>{this.props.firstName}</td>
      </ReactCSSTransitionGroup>
      <td>{this.props.lastName}</td>
    </tr>
  </tbody>  
</table>

这里的问题是 ReactCSSTransitionGroup 呈现为跨度,它不是表格行的有效子级。那么 React 是否可以在表格单元格上设置进入/离开动画?

4

1 回答 1

7

component如果您希望使用该属性,可以指定 React CSS Transitions 使用与 span 不同的容器元素。

http://facebook.github.io/react/docs/animation.html#rendering-a-different-component

如果这不起作用,我建议不要使用表格而是使用 div,也许使用 display: table/table-row/table-cell。

于 2014-09-14T00:51:20.933 回答