Javascript 如果在React 15中嵌套2,最好的方法是什么?
我想知道是否可以在ReactJSJSX中执行嵌套的2个如果? 我尝试过各种不同的方法,但我无法让它发挥作用。 我只尝试了一个元素,它是有效的。一旦我放入元素,我的代码就会中断Javascript 如果在React 15中嵌套2,最好的方法是什么?,javascript,reactjs,react-router,Javascript,Reactjs,React Router,我想知道是否可以在ReactJSJSX中执行嵌套的2个如果? 我尝试过各种不同的方法,但我无法让它发挥作用。 我只尝试了一个元素,它是有效的。一旦我放入元素,我的代码就会中断 <div> { (() => { if (VerticalRole === "Software Developer") <
<div>
{
(() => {
if (VerticalRole === "Software Developer")
<div>
<label>GITHUB ACCOUNT</label>
<div className="value">
<input
type="text"
name="github_url"
className="lowercase"
defaultValue={this.props.talent.github_url}
onChange={this.onChangeInput.bind(this)}
/>
</div>
</div>
if (MarketVetical === "Creative/Marketing")
<div>
<label>Portfolio Website</label>
<div className="value">
<input
type="text"
name="github_url"
className="lowercase"
defaultValue=
{this.props.talent.personal_website}
onChange={this.onChangeInput.bind(this)}
/>
</div>
</div>
})()
}
</div>
{
(() => {
if(垂直角色==“软件开发人员”)
GITHUB帐户
if(MarketVetical==“创意/营销”)
投资组合网站
})()
}
您可以尝试使用三元运算符:
<div>
{
VerticalRole === "Software Developer" ?
<div>
<label>GITHUB ACCOUNT</label>
<div className="value">
<input
type="text"
name="github_url"
className="lowercase"
defaultValue={this.props.talent.github_url}
onChange={this.onChangeInput.bind(this)}
/>
</div>
</div>
: MarketVetical === "Creative/Marketing" ?
<div>
<label>Portfolio Website</label>
<div className="value">
<input
type="text"
name="github_url"
className="lowercase"
defaultValue=
{this.props.talent.personal_website}
onChange={this.onChangeInput.bind(this)}
/>
</div>
</div>
: null
}
</div>
{
VerticalRole==“软件开发人员”?
GITHUB帐户
:MarketVetical==“创意/营销”?
投资组合网站
:null
}
这是有效的,我看到三元运算符是多么有用