亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 React Native 中將 JSON 數據傳遞到下一頁

在 React Native 中將 JSON 數據傳遞到下一頁

素胚勾勒不出你 2021-07-06 13:01:47
我是初學者,仍在學習如何對本機做出反應。在我的本機應用程序中,我有 2 個屏幕。在第一頁,我有 JSON 數據 [從實時服務器獲取];我想將此 JSON 數據傳遞到下一頁。我使用 react-navigation 在頁面之間導航。我將一個數據[手機號碼] 傳遞到下一頁。但我想不通,如何將 JSON 數據傳遞到下一頁!第一頁代碼:[其中包含 JSON 數據]constructor(props) {     super(props)     this.state = {    UserMNO: ''    }   }  UserLoginFunction = () =>{ const { UserMNO } = this.state; const {firstname} = this.state; const {lastname} = this.state; const {email} = this.state; const {profession} =this.state;fetch('http://demo.weybee.in/react/User_Login.php', {  method: 'POST',  headers: {    'Accept': 'application/json',    'Content-Type': 'application/json',  },  body: JSON.stringify({  mobileno: UserMNO,      })}).then((response) => response.json())      .then((responseJson) => {        // If server response message same as Data Matched       if(responseJson != 'Enter valid phone number' )        {               console.log(responseJson[0]);            console.log(responseJson[1]);            console.log(responseJson[2]);            console.log(responseJson[3]);            //Then open Profile activity and send user email to profile activity.            this.refs.toast.show('Login successful', 500, () => {            const { navigation } = this.props;            const { UserMNO }  = this.state ;            navigation.navigate("Profile",              {mobileno : UserMNO},              );    });        }        else{          Alert.alert(responseJson);        }      }).catch((error) => {        console.error(error);      });  }
查看完整描述

1 回答

?
拉丁的傳說

TA貢獻1789條經驗 獲得超8個贊

您可以像這樣發送響應 JSON:


navigation.navigate(

              "Profile", 

              {mobileno: UserMNO, myJSON: responseJson} 

);

并在第二個屏幕中獲取它:


const responseJson = this.props.navigation.getParam("myJSON");


查看完整回答
反對 回復 2021-07-08
  • 1 回答
  • 0 關注
  • 262 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號