如何将属性数组(产品的子数组)映射到选择器中。这是我的 JSON 数据:
{“产品”:[{“productid”:“5466”,“名称”:“腰果”,“描述”:“”,“属性”:[{“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}
/>
请帮助我提前谢谢