将本机推送数据反应到另一个屏幕

时间:2018-02-01 09:44:34

标签: react-native react-native-android react-native-ios react-native-navigation

我是React Native的新手,我正试图将数据从一个屏幕推送到另一个屏幕。我现在有两个屏幕,ProductListing& ProductDetail和虚拟条目列表。在我的ProductListing屏幕上,我执行了以下操作:

pushProductDetailScreen(item){

  this.props.navigator.push({
    screen: 'ProductDetail',
    title: item.name,
    subtitle: item.type,
    backButtonTitle: '',
    data: item
  });
 };

  <FlatList
        data={S_Entries}
        renderItem={({ item }) => (
          <ListItem
            roundAvatar
            title={item.name}
            subtitle={item.type}
            avatar={{ uri: item.image }}
            containerStyle={{ borderBottomWidth: 0 }}
            button onPress={() => {this.pushProductDetailScreen(item)}}
          />
        )}
        keyExtractor={item => item.id}
      />

在我的ProductDetail屏幕上,我想收到我的项目数组,并且不知道如何获得它。

1 个答案:

答案 0 :(得分:1)

使用passProps

example

ProductListing.js

  this.props.navigator.push({
    screen: 'ProductDetail',
    title: item.name,
    subtitle: item.type,
    backButtonTitle: '', 
    passProps: {   
       data: item
    },
  }); 

ProductDetail.js

var data = this.props.data;