【问题标题】:React native push data to another screen将本机推送数据反应到另一个屏幕
【发布时间】:2018-02-01 09:44:33
【问题描述】:

我是 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 屏幕上,我想收到我的商品数组,但不知道如何获得它。

【问题讨论】:

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


    【解决方案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;
    

    【讨论】:

    • 完美!谢谢
    猜你喜欢
    • 2021-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 2020-06-14
    • 2020-07-04
    相关资源
    最近更新 更多