Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果在React 15中嵌套2,最好的方法是什么?_Javascript_Reactjs_React Router - Fatal编程技术网

Javascript 如果在React 15中嵌套2,最好的方法是什么?

Javascript 如果在React 15中嵌套2,最好的方法是什么?,javascript,reactjs,react-router,Javascript,Reactjs,React Router,我想知道是否可以在ReactJSJSX中执行嵌套的2个如果? 我尝试过各种不同的方法,但我无法让它发挥作用。 我只尝试了一个元素,它是有效的。一旦我放入元素,我的代码就会中断 <div> { (() => { if (VerticalRole === "Software Developer") <

我想知道是否可以在ReactJSJSX中执行嵌套的2个如果? 我尝试过各种不同的方法,但我无法让它发挥作用。 我只尝试了一个元素,它是有效的。一旦我放入元素,我的代码就会中断

              <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
}

这是有效的,我看到三元运算符是多么有用