Json react本机dry条件语句
我有下面的代码,这是所有的罚款和工作,但我在看如何我可以更好地生产这一点,使其干燥,如果我可以结合所有的定制等将是aceJson react本机dry条件语句,json,firebase,react-native,dry,Json,Firebase,React Native,Dry,我有下面的代码,这是所有的罚款和工作,但我在看如何我可以更好地生产这一点,使其干燥,如果我可以结合所有的定制等将是ace render() { let sizeHeader,milkHeader = null; this.props.data.size ? sizeHeader = <Text style={styles.headerLabel}>Size</Text> : null this.props.data.milk ? milkHeade
render() {
let sizeHeader,milkHeader = null;
this.props.data.size ? sizeHeader = <Text style={styles.headerLabel}>Size</Text> : null
this.props.data.milk ? milkHeader = <Text style={styles.headerLabel}>Milk</Text> : null
return (
<View style={styles.container}>
<ParallaxScrollView>
<View>
{sizeHeader}
{(this.props.data.size||[]).map((section,i) => (
<AddToCartRow key={i} data={section} productName={this.props.data.name} value={Config.priceToPriceWithCurrency(section.price)} />
))}
{milkHeader}
{(this.props.data.milk||[]).map((section,i) => (
<AddToCartRow key={i} data={section} productName={this.props.data.name} value={Config.priceToPriceWithCurrency(section.price)} />
))}
</View>
</ParallaxScrollView>
<RoundedButton onPress={()=>{NavigationActions.CartAndCheckout()}}>
Go to Cart
</RoundedButton>
</View>
);
}
我是否需要向它传递任何参数?或者
milk
或者size
,那么我实际上如何将这些参数传递给这段代码?似乎仍然不起作用,只是在执行控制台操作时返回未定义的参数。log@Paul“Whippet”McGuane您是说键是未定义的
?
{
"Merchants" : {
"items" : [ {
"address" : "address here",
"items" : [ {
"description" : "Silky frothed milk poured over a shot of espresso, topped with a touch of chocolate.",
"info" : {
"Calories" : "250 kcal",
"Glutten Free" : "Yes"
},
"milk" : [ {
"name" : "Full Cream",
"price" : 0
}, {
"name" : "Almond",
"price" : ".5"
}, {
"name" : "Coconut",
"price" : ".5"
}, {
"name" : "Soy",
"price" : ".5"
}, {
"name" : "Cunt",
"price" : 5
} ],
"name" : "Cappuccino",
"photo" : "https://upload.wikimedia.org/wikipedia/commons/e/ed/Wet_Cappuccino_with_heart_latte_art.jpg",
"price" : 10.0,
"size" : [ {
"name" : "Small",
"price" : 10
}, {
"name" : "Medium",
"price" : 18
} ]
}
_renderContent = (key) => (
<View>
{this.props[key] && <Text style={styles.header}>{`${key.charAt(0).toUppercase()}${key.slice(1)}`}</Text>}
{(this.props[key] || []).map(section, i) => (
<AddToCartRow
key={i}
data={section}
productName={this.props.data.name}
value={Config.priceToPriceWithCurrency(section.price)}
/>
)}
</View>
);
<ParallaxScrollView>
<View>
{['milk', 'size'].map(this._renderContent)}
</View>
</ParallaxScrollView>