我正在尝试使用内联 if 语句来检查一条数据是否存在以及是否显示它。这段代码目前位于我的渲染、返回块中。
我遇到的问题是使用这个,内容不再被呈现
{(() => {
if (this.props.data.size) {
<Text style={styles.headerLabel}>Sizes</Text>
{(this.props.data.size||[]).map((section,i) => (
<AddToCartRow key={i} data={section} productName={this.props.data.name} value={Config.priceToPriceWithCurrency(section.price)} />
))}
}
})()}
render(){
return(
<View>
{this.state.error && <Text style={{ color: 'red' }}>{this.state.errorMessage}</Text>}
<Text>Hello World!</Text>
</View>
);
}
你去吧。
哦对不起。我刚刚点击了上面的“运行代码片段”按钮,结果显示了一个错误。但我认为这与您的代码无关。对不起。