2017-04-16 94 views
0

如何执行内嵌嵌套if语句在阵营查看,如何在React Component中执行内联嵌套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)}> 
+0

我想你应该避免这种情况,你失去了这么多的可读性。我会把它放到一个专门的功能 – soywod

+0

他们是新作出的改变,所以我必须按照相同的方式 – Gopinath

回答

0

你缺少嵌套否则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):"")}> 
+0

不工作的Ved :( – Gopinath

+0

@VickySmart检查我的更新的答案 – Ved

+0

伟大的Ved ...这是解决方案... :)感谢您的时间 – Gopinath