react native 不同页面之间传参 传值 __listview列表跳转详情页 带参数 传值
2016-12-21 11:28
645 查看
负责跳转的导航页:ListDefault.js
页面1 :GoodsList.js
页面2:GoodsDetail.js
'use strict'; import React, { Component } from 'react'; import{ View, Navigator } from 'react-native'; import GoodsList from './GoodsList'; class ListDefault extends Component{ render(){ var defaultName='GoodsList'; var defaultComponent=GoodsList; return( <Navigator initialRoute={{name:defaultName,component:defaultComponent}} configureScene={(route)=>{ return Navigator.SceneConfigs.HorizontalSwipeJump; }} renderScene={(route,navigator) =>{ let Component = route.component; return <Component{...route.params} navigator={navigator}/> }}/> ); } } module.exports=ListDefault;
页面1 :GoodsList.js
class GoodsList extends Component { constructor(props) { super(props); // 初始状态 this.state = { loaded :false, dataSource : new ListView.DataSource({ rowHasChanged:(row1,row2) => row1 !== row2, }), }; } componentDidMount(){ this._fetchListData(); } _fetchListData(){ //fetch网络加载数据后面单独讲,此处略 } _renderLoadingView(){ return( <View style={{flex:1, justifyContent:'center',alignItems:'center',backgroundColor:'#F5FCFF'}}> <Text>Loading GoodsList data .....</Text> </View> ) } _renderRow(item){ return( <TouchableHighlight onPress = { this._pressRow.bind(this,item)} > <View style={[styles.listContainer,{justifyContent:'flex-start',alignItems:'flex-start', }]}> <View style={[styles.leftContainer,{justifyContent:'space-around',alignItems:'center'}]}> <Image source={require('../images/logistics/siji_protrait.png')} style={styles.siji_protrait}/> <Text>{item.realName}</Text> <Image source={callPhoneImage.src} style={styles.image_uri}/> </View> <View style={styles.rightContainer}> <View> <Text>{item.updateTime}</Text> </View> <View > <Text sytle={styles.title}>{item.origin}</Text> <Text sytle={styles.title}>{item.destination}</Text> <Text sytle={styles.title}>{item.carType}</Text> <Text sytle={styles.title}>{item.goodsWeight} 吨</Text> <Text>00001</Text> </View> </View> </View> </TouchableHighlight> ); _pressRow(item){ const {navigator} =this.props; if(navigator){ navigator.push({ name:'GoodsDetail', component:GoodsDetail, params:{ item:item, } }) } } _renderHeader(){ return( <View>header</View> ) } render(){ console.log("goodslist render .if before....") if (!this.state.loaded){ return this._renderLoadingView(); } return( <ListView //enableEmptySections={true} dataSource={this.state.dataSource} renderRow={this._renderRow.bind(this)} style={styles.listView} /> ); } } const styles = StyleSheet.create({ container: { flex: 1, flexDirection: 'column', justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, listView: { flex:1, paddingTop: 20, backgroundColor: '#F5FCFF', }, thumbnail: { width: 53, height: 81, }, listContainer:{ flex:1, flexDirection:'row', borderWidth: 1, borderColor: '#eeeeee', }, leftContainer:{ flex:1, flexDirection:'column' }, rightContainer: { flex: 3, }, title: { fontSize: 20, marginBottom: 8, textAlign: 'center', }, siji_protrait:{ height:60, resizeMode:'cover' }, image_uri:{ height:35, resizeMode:'cover', }, year: { textAlign: 'center', }, }); module.exports=GoodsList;
页面2:GoodsDetail.js
class GoodsDetail extends Component{ constructor(props){ super(props); this.state={ itemValue:"id占用位置" }} componentDidMount(){ this.setState({ itemValue:this.props.item, }); } _pressBack(){ const{navigator} = this.props; if(navigator){ navigator.pop(); } } render(){ return( <View style={styles.container}> <View> <TouchableHighlight onPress={this._pressBack.bind(this)} style={{margin:20}}> <Text>返回</Text> </TouchableHighlight> </View> <Text>detail</Text> <Text>item=={this.state.itemValue.origin}</Text> </View> )} }
相关文章推荐
- ReactNative官网例子练习(五)——页面跳转传参
- 两个不同编码的页面之间的参数传递( 解码 )
- javascript在页面之间传参时,路径参数中出现反斜杠的处理
- .jsp与servlet之间页面跳转及参数传递实例
- 11. jsp与servlet之间页面跳转及参数传递实例
- 不同应用之间的页面跳转
- asp.net不同页面之间的调用及传参数
- Android 之不同Activity间页面的跳转与传递参数
- (转载)jsp与servlet之间页面跳转及参数传递实例
- StoryBoard页面联线跳转已经页面之间传参数
- React-native页面跳转传值实现
- Silverlight - Xaml 和 asp.net 页面之间跳转及参数传递
- .net C#中页面之间传值传参的六种方法(转) 传递简单参数
- JAVASCRIPT AND C#.NET2.0 之间的传参问题(静态页面,动态页面,传参数,编码,乱码)
- 两个不同HTML页面之间参数传递
- Windows Phone 7 Tip - 不同页面之间的参数传递
- iPhone不同页面之间跳转
- Windows Phone 7 Tip - 不同页面之间的参数传递【转】
- Android 自定义Permission实现不同应用之间页面跳转
- js 页面之间的跳转、传参以及返回上一页