首页 > 解决方案 > 从数组的索引 0 显示图像反应本机

问题描述

我正在使用 firebase 并为应用程序做出原生反应。帖子已保存,因此“图像”字段是多个图像的数组。但我只想显示第一张图片(索引 0)并且无法让它工作。

非常感谢您的帮助

   return ( 
      <View style={styles.container}>
        

        <View style={styles.gallery}>
            <FlatList
                numColumns={3}
                horizontal={false}
                data={posts}
                renderItem={({ item }) => (
                    <View
                        style={styles.imageContainer}>

                        <Text>{item.name}</Text>
                        <TouchableOpacity 
                                onPress={() => props.navigation.navigate('PostPage', { postId: item.id})}>
                        <Image
                                style={styles.image}
                                source={{ uri: item.images[0] }} //-> fetched from firebase firestore
                                />
                        </TouchableOpacity>
                    </View>

                )}

            />
        </View>
    </View>

  )
  } 

标签: reactjsfirebaseimagereact-native

解决方案


推荐阅读