2017-04-08 81 views
0

我写了一个if if null见下文,它工作正常。React Native - If else null not working

{this.state.tomorrow.length > 0 ? 
    <ListItem itemDivider style={{backgroundColor: 'crimson'}}> 
     <Text style={{color: 'white'}}>Tomorrow</Text> 
    </ListItem> : null 
} 

然后我在另一页上写了这个,它不工作,我做错了什么?

<Grid>         
    <Row style={{paddingBottom:10}}> 
     <Col> 
      <Text>Location:</Text> 
     </Col> 
     <Col> 
      <Text>{ this.state.appointment.location }</Text> 
     </Col> 
    </Row> 
    {this.state.appointment.location_bool ? <Text>Hello</Text> : null } 
</Grid> 

错误我得到的是:

无法读取空的特性 '类型'

感谢

+0

第二部分是没有这条线的工作:'{此.state.appointment.location_bool? 你好:null}'??我认为问题在别的地方,你在任何地方使用类型? –

+0

@MayankShukla是的,没有这条线就可以正常工作 - 不会在任何地方使用类型。 –

+0

通过任何API调用从服务器获取'约会'数据? –

回答

0
<Grid>         
    <Row style={{paddingBottom:10}}> 
     <Col> 
      <Text>Location:</Text> 
     </Col> 
     <Col> 
      <Text>{ this.state.appointment.location }</Text> 
     </Col> 
    </Row> 
     <Row> 
      { 
      this.state.appointment.location_bool ? 
       <Col> <Text> Hello </Text> </Col> 
       : 
       null 
      } 
     </Row> 
</Grid> 
+0

这工作,多么奇怪,谢谢! –

+0

太好了。乐于帮助。 – Ved

+0

任何解释,为什么这个工程,鉴于它看起来语法上不正确的给定围绕三元操作符缺少关闭花括号...... – Pineda