使用listview在react-native中处理数组

Handle arrays in react-native withouth listview

本文关键字:处理 数组 react-native listview 使用      更新时间:2023-09-26

我对react-native很陌生,我已经设法获得了详细信息页面的项目列表,但我还没有找到任何解决方案,我如何在详细信息页面上加载字符串数组而不使用listview

我有一个数组的图像url,我如何显示这些?也许我没有抓住重点,我过于关注Angular中的ng-repeat

我想看的:

<View>
 <Text>{item.title}</Text>
 <Text>{item.description}</Text>
 <Image></Image> //image 1
 <Image></Image> //image 2
 <Image></Image> //image 3
</View>

您可以映射图像并将它们存储在一个变量中,然后在返回语句中使用该变量:

const images = arrayOfImages.map((image, i) => {
    return <Image
             key={i}
             source={{uri: image}}
             style={styles.image} />
})

然后像这样使用数组:

<View>{images}</View>

我在这里设置了一个工作示例以获得更多上下文。

https://rnplay.org/apps/f6A5NQ