如何在 React 组件中执行内联嵌套的 if 语句?
How to Perform Inline nested if statement in React Component?
如何在 React View 中执行内联嵌套 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)}>
您缺少嵌套 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):"")}>
如何在 React View 中执行内联嵌套 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)}>
您缺少嵌套 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):"")}>