如何在React组件中执行内联嵌套if语句?

时间:2017-04-16 16:59:52

标签: reactjs redux ternary-operator

如何在React View中执行嵌套if if,

例如

true ? function a()  : function b() 

以上格式工作正常,但我需要执行嵌套,如下例所示

例如

true ? true : function a () :  true :function b()

我的工作代码

  <div onClick={()=> this.props.materials.is_table_clicked  ? this.handleLocal() : this.props.enableMaterialTable(this.props.materials)}>

尝试嵌套但是没有工作

<div onClick={()=> this.props.materials.is_table_clicked  ? this.handleLocal() : this.props.audio.playing ? this.props.enableMaterialTable(this.props.materials)}>

1 个答案:

答案 0 :(得分:0)

你缺少嵌套的else的else条件。

 : (this.props.audio.playing ? 
this.props.enableMaterialTable(this.props.materials):""//You missing this

应该有效:

 <div onClick={()=> this.props.materials.is_table_clicked  ? 
    this.handleLocal() : (this.props.audio.playing ? 
this.props.enableMaterialTable(this.props.materials):"")}>
相关问题