【问题标题】:Is it possible to set a CSSTransitionGroup on a table cell in ReactJS?是否可以在 ReactJS 中的表格单元格上设置 CSSTransitionGroup?
【发布时间】:2014-11-07 09:23:27
【问题描述】:

考虑这个 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 是否可以在表格单元格上设置进入/离开动画?

【问题讨论】:

    标签: css css-transitions react-jsx


    【解决方案1】:

    如果您愿意,可以使用 component 属性指定 React CSS 过渡使用与 span 不同的容器元素。

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

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

    【讨论】:

    • 我刚刚删除了包装 并且它似乎工作正常(是的,它之前在 Firefox 中很古怪)。 {rows}
    • 现在在firefox中遇到同样的问题..当我在firebug中禁用背景颜色并再次启用它时,它可以工作......嗯..你找到解决方案了吗?
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签