我已经硬编码了一些数据并做了一个映射来获取数组的所有数据, 除我的图像外,所有数据均已显示。 我尝试了几种解决方案,但没有任何效果。 当我使用带有字符串中的图像路径的 require 时,它可以工作,但我找不到显示不同图像的方法 有什么想法吗?
var articleData = [
{ name: "Textile motorcycle jacket", brand: "Dainese", img: "../assets/Jacket.jpg", price: '200' },
{ name: "Summer motorcycle gloves", brand: "Furygan", img: "../assets/summer_gloves.jpg", price: '30' },
{ name: "Winter motorcycle gloves", brand: "Triumph", img: "../assets/winter_gloves.jpg", price: '70' },
{ name: "Motorcycle boots", brand: "BMW", img: "../assets/boots.jpg", price: '180' },
{ name: "Goretex / waterproof pants", brand: "Dainese", img: "../assets/pants.jpg", price: '150' },
{ name: "Back and safety protection", brand: "Dainese", img: "../assets/back_protection.jpg", price: '100' },
]
var ArticleList = articleData.map((article, i) => {
return (<View style={{ width: '47%', margin: 5 }}>
<Image source={{uri: article.img}} style={{ height: 250, width: 200}} />
<View style={{ flex: 1, flexDirection: 'row', marginTop: 5, justifyContent: "space-between" }}>
<Text style={{ fontWeight: 'bold' }}>{article.brand}</Text>
<FontAwesome name="heart" size={20} color={colorLike} />
</View>
<Text>{article.name}</Text>
<Text>{article.price}€</Text>
</View>
)
}
)
最佳答案
您可以尝试将 require 添加到文章数据中,如下所示
{ name: "Textile motorcycle jacket", brand: "Dainese", img: require("../assets/Jacket.jpg"), price: '200' }
关于在 native react 中使用 map 功能时,图像不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65464826/