【问题标题】:Nested conditional rendering in jsx Reactjsx React 中的嵌套条件渲染
【发布时间】:2020-06-04 13:35:54
【问题描述】:

我试图在 jsx 本身中有一个嵌套的 if 条件。这是我的代码示例:

        {this.props.customerInformation?
           <Descriptions title="Customer Information" bordered>
           {this.props.customerInformation.customer_status.label}</Descriptions.Item>
            </Descriptions>
            :
            <Button> Create a new customer </Button>
            }

我试图做的是在顶部条件中添加另一个条件,看起来像这样:

            {this.props.customerInformation?
           <Descriptions title="Customer Information" bordered>
          <Descriptions.Item>
           {this.props.customerInformation.customer_status.label}
          </Descriptions.Item>

               <Description.Item>
             {this.props.customerInformation.poc?
              <Descriptions title="poc" > 
              {this.props.customerInformation.poc}
              <Descriptions.Item>
             </Descriptions>
            :
            <Button> Create a new customer </Button>
            }

【问题讨论】:

    标签: reactjs


    【解决方案1】:

    添加括号来包装您的代码。

     {this.props.customerInformation?
               (<Descriptions title="Customer Information" bordered>
                  {this.props.customerInformation.customer_status.label} 
                   </Descriptions.Item>
                </Descriptions>)
                :
                (<Button> Create a new customer </Button>)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-11
      • 1970-01-01
      • 2019-08-01
      • 2020-10-12
      • 2018-10-16
      • 2018-06-25
      • 2016-06-20
      • 1970-01-01
      相关资源
      最近更新 更多