【问题标题】:Dynamic className in cjsxcjsx中的动态类名
【发布时间】:2015-08-31 03:40:57
【问题描述】:

当我单击所述按钮时,我试图隐藏组件并更新按钮中的图像。我已经设法通过执行以下操作来隐藏组件:

{<MyAwesomeComponent /> unless @state.hide}

我通过以下方式更改状态:

toggleComponent = ->
  @setState
    hide: !@state.hide

. . . 

<div 
  onClick={@toggleComponent}>
  <img 
    src="img/interface/icon-chevron-left.png"
    className={if @hide then "hidden"}/>
</div>

不幸的是,{if @hide then "hidden"} 似乎不起作用。关于如何做到这一点的任何想法?

【问题讨论】:

    标签: coffeescript reactjs


    【解决方案1】:

    隐藏属性设置在@state,而不是组件实例上。

    if @state.hide then "hidden"
    

    【讨论】:

    • 是的,这就是问题所在。谢谢:)
    猜你喜欢
    • 2015-02-27
    • 2023-04-07
    • 2018-07-13
    • 2011-05-22
    • 2023-04-04
    • 2017-03-13
    • 2014-01-15
    • 1970-01-01
    • 2013-04-14
    相关资源
    最近更新 更多