【发布时间】:2020-12-02 07:34:15
【问题描述】:
如何将属性数组(产品的子数组)映射到选择器中。 这是我的 JSON 数据:
{ "products": [ { "productid": "5466", "name": "Cashew", “描述”:“”,“属性”:[{“product_id”:“5466”, “attribute_name”:“500 grm”,“attribute_price”:“500”},{ “product_id”:“5466”、“attribute_name”:“250 grm”、“attribute_price”: "250" } ] } ] }
这是我的代码:
renderProductsCart = ({ item }) => {
return (
<View style={{ width: "46%", marginLeft: 10, marginTop: 10 }}>
<Card
elevation={2}>
<Card.Cover source={{ uri: item.image }} />
<Text style={{ marginLeft: 5 }}>{item.name}</Text>
<Text> ₹: {item.attribute_price}/- </Text>
<Picker
selectedValue={this.state.PickerValueHolder}
onValueChange={(itemValue, itemIndex) => this.setState({ PickerValueHolder: itemValue })} >
{this.state.data.products.attributes.map((item, key) => (
<Picker.Item label={item.attribute_name} value={item.attribute_name} key={item} />)
)}
</Picker>
<View style={{ flexDirection: "row" }}>
<Card.Actions>
<Button
theme={{ colors: { primary: 'black' } }}
onPress={() => console.log("press")}>View More</Button>
<Button
theme={{ colors: { primary: 'black' } }}
onPress={() => console.log("press")}>Cart</Button>
</Card.Actions>
</View>
</Card>
</View>
)
}
<FlatList
data={this.state.data.products}
renderItem={this.renderProductsCart}
keyExtractor={(item, index) => index.toString()}
numColumns={2}
/>
请帮帮我 提前致谢
【问题讨论】:
标签: react-native mapreduce react-native-android react-native-flatlist react-native-picker-select