詳解js界面跳轉(zhuǎn)與值傳遞
本文實(shí)例實(shí)現(xiàn)的功能如下:注冊(cè)頁(yè)(Register.js),點(diǎn)擊注冊(cè),跳到注冊(cè)結(jié)果頁(yè)(RegisterResult.js),并將注冊(cè)的手機(jī)號(hào)傳遞過(guò)去,顯示xx注冊(cè)成功。
index.Android.js
'use strict' import React, { Component } from 'react'; import { AppRegistry,Navigator,BackAndroid} from 'react-native'; var Register = require('./study/Register'); let RegisterResult = require('./study/RegisterResult'); var NaviModule = React.createClass({ //告知Navigator模塊,我們希望在視圖切換時(shí),用什么效果 configureScene:function(route){ return Navigator.SceneConfigs.FadeAndroid; }, //告知Navigator模塊,我們希望如何掛接當(dāng)前視圖 renderScene:function(router,navigator){ this._navigator = navigator; switch(router.name){ case "register": return <Register navigator = {navigator}/> case "registerResult": return <RegisterResult telephoneNumber = {router.telephoneNumber} navigator = {navigator}/> } }, //React的生命周期函數(shù)---組件被掛接時(shí)調(diào)用 componentDidMount:function(){ var navigator = this._navigator; BackAndroid.addEventListener('NaviModuleListener',()=>{ if (navigator && navigator.getCurrentRoutes().length > 1) { navigator.pop(); return true; } return false; }); }, //React的生命周期函數(shù)---組件被移除時(shí)調(diào)用 componentWillUnmount: function(){ BackAndroid.removeEventListener('NaviModuleListener'); }, render:function(){ return ( <Navigator initialRoute = {{name:'register'}} configureScene = {this.configureScene} renderScene = {this.renderScene} /> ); } }); AppRegistry.registerComponent('FirstDemo', () => NaviModule);
注冊(cè)頁(yè)(Register.js)
'use strict' import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, TextInput } from 'react-native'; let Dimensions = require('Dimensions'); let totalWidth = Dimensions.get('window').width; let leftStartPoint = totalWidth * 0.1; let componetWidth = totalWidth * 0.8; let Register = React.createClass({ getInitialState:function(){ return { inputedNum :'', inputedPW:'', }, updatePW: function(newText){ this.setState({inputedPW : newText}); }, render: function() { return ( <View style={styles.container}> <TextInput style = {styles.numberInputStyle} placeholder = {'請(qǐng)輸入手機(jī)號(hào)'} onChangeText = {(aa) => this.setState({inputedNum :aa})}/> <Text style={styles.textPromptStyle}> 您輸入的手機(jī)號(hào):{this.state.inputedNum} </Text> <TextInput style={styles.passwordInputStyle} placeholder = {'請(qǐng)輸入密碼'} password = {true} onChangeText = {(newText) => this.updatePW(newText)}/> <Text style={styles.bigTextPrompt} onPress = {this.userRegister}> 注 冊(cè) </Text> </View>); }, userRegister:function(){ this.props.navigator.replace({ telephoneNumber : this.state.inputedNum, name: 'registerResult', }); } }); const styles = StyleSheet.create({ container: { flex: 1, flexDirection:'column', justifyContent: 'center', backgroundColor: '#F5FCFF', }, numberInputStyle:{ top:20, left:leftStartPoint, width:componetWidth, backgroundColor:'gray', fontSize:20 }, textPromptStyle:{ top:30, left:leftStartPoint, width:componetWidth, fontSize:20 }, passwordInputStyle:{ top:50, left:leftStartPoint, width:componetWidth, backgroundColor:'gray', fontSize:20 }, bigTextPrompt:{ top:70, left:leftStartPoint, width:componetWidth, backgroundColor:'gray', color:'white', textAlign:'center', fontSize:60 } }); module.exports = Register;
注冊(cè)結(jié)果頁(yè)RegisterResult.js
'use strict' import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, TextInput } from 'react-native'; let RegisterResult = React.createClass({ render:function(){ return( <View style = {styles.container}> <Text style = {styles.text}> {this.props.telephoneNumber}注冊(cè)成功 </Text> </View> ); } }); const styles = StyleSheet.create({ container: { flex: 1, flexDirection:'column', justifyContent: 'center', alignItems:'center', backgroundColor: '#F5FCFF', }, text:{ flexWrap:'wrap', backgroundColor:'gray', fontSize:20, paddingTop:10, paddingBottom:10, paddingLeft:25, paddingRight:25 }, }); module.exports = RegisterResult;
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
判斷div滑動(dòng)到底部的scroll實(shí)例代碼
下面小編就就為大家分享一篇判斷div滑動(dòng)到底部的scroll實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-11-11詳解CocosCreator系統(tǒng)事件是怎么產(chǎn)生及觸發(fā)的
這篇文章主要介紹了CocosCreator系統(tǒng)事件是怎么產(chǎn)生及觸發(fā)的,雖然內(nèi)容不少,但是只要一點(diǎn)點(diǎn)抽絲剝繭,具體分析其內(nèi)容,就會(huì)豁然開(kāi)朗2021-04-04JavaScript Ajax實(shí)現(xiàn)異步通信
這篇文章主要為大家詳細(xì)介紹了JavaScript Ajax實(shí)現(xiàn)異步通信的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12網(wǎng)頁(yè)中可關(guān)閉的漂浮窗口實(shí)現(xiàn)可自行調(diào)節(jié)
廣告式的漂浮窗口,想必大家并不陌生吧,下面為大家簡(jiǎn)單介紹下具體的實(shí)現(xiàn),有需要的朋友可以參考下2013-08-08zTree獲取當(dāng)前節(jié)點(diǎn)的下一級(jí)子節(jié)點(diǎn)數(shù)實(shí)例
下面小編就為大家?guī)?lái)一篇zTree獲取當(dāng)前節(jié)點(diǎn)的下一級(jí)子節(jié)點(diǎn)數(shù)實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09window.open打開(kāi)窗口被攔截的快速解決方法
下面小編就為大家?guī)?lái)一篇window.open打開(kāi)窗口被攔截的快速解決方法。覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08JavaScript垃圾回收機(jī)制(引用計(jì)數(shù),標(biāo)記清除,性能優(yōu)化)
這篇文章主要介紹了JavaScript垃圾回收機(jī)制(引用計(jì)數(shù),標(biāo)記清除,性能優(yōu)化),垃圾回收是JavaScript的隱藏機(jī)制,我們通常無(wú)需為垃圾回收勞心費(fèi)力,只需要專(zhuān)注功能的開(kāi)發(fā)就好了2022-07-07