【发布时间】:2019-07-14 10:07:40
【问题描述】:
我有一个屏幕,其中包含一组对象,其中包含图像路径等信息。我希望在屏幕加载时从另一个屏幕检索此屏幕的数据。
我真的很困惑如何检索数据,因为大多数人是在传递数据而不是检索数据。我有照片来说明我在问什么。
这里有来自我的 1stScreen 的对象。然后在我的 2ndScreen 中,我希望将 1stScreen 中的 imageSource 渲染为 item.imageSource 作为图像列表。如何从 1stScreen 检索对象以在 2ndScreen 中访问它们?
第一屏
import React from 'react';
import { StyleSheet, View, FlatList, ScrollView } from 'react-native';
export default class CaterpillarObjectList extends React.Component {
render() {
const blackswallowtailimageList =
[{key:'blackSwallowTail01', imageSource: require('../assets/ArboretumPhotos/Black_Swallowtail/blackswallowtail1.jpg')},
{key:'blackSwallowTail02', imageSource: require('../assets/ArboretumPhotos/Black_Swallowtail/blackswallowtail2.jpg')},
{key:'blackSwallowTail03', imageSource: require('../assets/ArboretumPhotos/Black_Swallowtail/blackswallowtail3.jpg')},];
第二屏
(注意:我在 2ndScreen 中调用了 imageList,但我想从 1stScreen 中检索 imageList 作为 blackswallowtailimageList)
{imageList.length > 0 ?
<FlatList horizontal = {true} data={imageList}
renderItem={({item})=> (
<View style={{borderBottomColor:'#999', padding:10}}>
<View>
<Image style ={ {width: 300, height: 300}} source={item.imageSource}/>
</View>
</View>
)} />
【问题讨论】:
-
你能把完整的代码贴在这里吗?
-
@TonyHoanTrinh 请将代码添加到您的问题中。你可以编辑它。
-
对不起,我是 StackOverFlow 的新手。我刚刚做了,谢谢!
标签: javascript android ios react-native mobile-application