我在 React Native Flatlist 中的 Picker 中检索了一些 JSON 数据,这些数据具有相同项目的两个以上属性,如下所示:
{"products":
[
{
"name": "Dried Blueberry",
"weight": "1000gm",
"price": "200"
},
{
"name": "Dried Blueberry",
"weight": "500gm",
"price": "100"
},
{
"name": "Dried Blueberry",
"weight": "250gm",
"price": "50"
}
]
}
它显示如下
但我想这样显示
有人会帮助我吗?
这是我的代码:
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.data}
onValueChange={(itemValue, itemIndex) => this.setState({ data: itemValue })} >
{/* {this.state.city.map((item, key) => (
<Picker.Item label={item.name} value={item.name} key={key} />)
)} */}
<Picker.Item label={item.attribute_name} value={item.attribute_name} />
</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.attributes}
renderItem={this.renderProductsCart}
keyExtractor={(item, index) => index.toString()}
numColumns={2}
/>