【发布时间】:2018-05-24 07:37:48
【问题描述】:
我想做什么
我每行最多只能补5张优惠券,如果超过5张优惠券我会移动到下一行。
如果 couponNum == 5
O O O O O
如果 couponNum == 12
O O O O O
O O O O O
噢噢
代码
<View style={styles.couponBox}>
{this.createCoupon(couponNum)}
</View>
const styles = StyleSheet.create({
couponBox: {
flex: 1,
flexDirection: 'row',
// alignItems: 'center',
alignSelf: 'center',
justifyContent: 'center',
backgroundColor: 'yellow',
width: width - 100,
height: height -200,
},
circle: {
width: 44,
height: 44,
borderRadius: 44/2,
backgroundColor: colors.lightFink,
alignItems: 'center',
justifyContent: 'center',
},
})
createCoupon = (couponNum) => {
let coupons = []
let i = 1;
while( i <= couponNum ) {
let children = []
children.push(
<View>
<View style={{width: 50, height: 50, margin: 5, }}>
<View style={styles.circle}>
<Text style={{fontSize: 16, }}>{i}</Text>
</View>
</View>
</View>
)
table.push(<View style={{flex: 2, flexDirection: 'row', }}>{children}</View>)
i++;
}
return coupons
}
但是这个代码是这样的错误..
如果 couponNum == 5
O O O O O
如果 couponNum == 12
呜呜呜呜呜
我应该怎么做才能解决这个问题?
【问题讨论】:
-
不要忘记在返回节点数组时添加
key属性<View key={somethingUniquePreferNotIndexIfPossible} ...>
标签: javascript react-native ecmascript-6