在 native react 中使用 map 功能时,图像不显示

标签 image react-native array.prototype.map

我已经硬编码了一些数据并做了一个映射来获取数组的所有数据, 除我的图像外,所有数据均已显示。 我尝试了几种解决方案,但没有任何效果。 当我使用带有字符串中的图像路径的 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/

相关文章:

python - Python 中的 PIL 提示 PixelAccess 没有 'size' 属性,我做错了什么?

javascript - 如何在 JavaScript 中匹配两个图像?

javascript - React Native - 从父组件重新渲染子组件

react-native - com.android.ide.common.process.ProcessException : Failed to execute aapt ERROR

javascript - 仅从数组中的每个对象中提取某些属性,然后添加到新数组中

javascript - 如何根据循环内的特定条件使用 Array.map 迭代停止索引计数递增?

java - 当我将 Url 中的图像设置为 recycleView 时,速度变慢,我该如何修复它?

iphone - 将图像加载到网格中时遇到问题

android - React Native无法确定任务 ':app:compileDebugJavaWithJavac'的依赖关系

arrays - Array.prototype.filter() 期望在箭头函数末尾返回一个值,React