簡體   English   中英

在wix react native navigation V2中如何將數據從一個屏幕傳遞到另一個

[英]In wix react native navigation V2 How to pass data from one screen to another

我在我們的 React Native 應用程序中使用Wix React Native Navigation V2 我遇到了將數據從一個屏幕傳遞到另一個屏幕的問題。 當我選擇FLATLIST的行時,第一個屏幕包含FLATLIST ,然后我需要在另一個屏幕上導航並傳遞行數據。

這是我的代碼:

屏幕 1:

此代碼在FLATLIST 上顯示行數據(工作正常)

_renderItem = ({ item }) => {
    const text = `${item}`;
    return (
      <TouchableOpacity onPress={() => this.moveToAnotherScreen(item)}>
        <View style={styles.cardView}>
          <Text style={styles.item2}>{item.name}</Text>
          <Text style={styles.item2}>{item.Type}</Text>
          <Text style={styles.item2}>{item.mobile}</Text>

        </View>
      </TouchableOpacity>
    );
  };

這是moveToAnotherScreen函數

moveToAnotherScreen(item) {
    Navigation.push(this.props.componentId, {
      component: {
        name: 'ShowAnotherScreen',

      },
      passProps: {
        data: item
    }
    });
  }

屏幕 2:

componentDidMount() {

    const params  = this.props.data
    console.log('params', params);
  }

您傳遞道具的語法是錯誤的。 試試下面

Navigation.push(this.props.componentId, {
      component: {
        name: "ShowAnotherScreen",
        passProps: {
         data: item
        }
      }
    })

Passprops 應該在component內部

moveToAnotherScreen(item) {
  Navigation.push(this.props.componentId, {
    component: {
      name: 'ShowAnotherScreen',
      passProps: {
        data: item
      }
    }
  });
}

在 ShowAnotherScreen

componentDidMount() {
  console.log(JSON.stringify(this.props.item))}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM