react native navigator.push传递参数,第二个界面接收不到

cwcwj3069 2017-06-28 06:11:06
react native navigator.push传递参数,第二个界面接收不到
项目配置"react": "16.0.0-alpha.6","react-native": "0.43.0",
下面是完整的配置文件:
{
"name": "ylt",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.0.0-alpha.6",
"react-native": "0.43.0",
"react-native-camera": "git+https://github.com/lwansbrough/react-native-camera.git",
"react-native-tab-navigator": "^0.3.3",
"react-native-vector-icons": "^4.2.0",
"react-redux": "^5.0.5",
"redux": "^3.7.1"
},
"devDependencies": {
"babel-jest": "20.0.3",
"babel-preset-react-native": "2.0.0",
"jest": "20.0.4",
"react-test-renderer": "16.0.0-alpha.6"
},
"jest": {
"preset": "react-native"
}
}


1-A界面push代码
onScan() {
const { navigator } = this.props;
navigator.push({
component: Scan,
title: 'Scan',
passProps: {
"code":"123456",
callback:((transCode)=>{
this.setState({transCode:transCode})[/color]
})
}
});
}

2-B界面获取参数代码,this.props.callback为undefined
barcodeReceived(e) {
if (e.data !== this.transCode) {
Vibration.vibrate([0, 500, 200, 500]);
this.transCode = e.data; // 放在this上,防止触发多次,setstate有延时
if(this.state.flag){
this.changeState(false);
//通过条码编号获取数据
}
if(this.props.callback){
this.props.callback(this.transCode);
}
console.log("transCode="+this.transCode);

this._goBack();
}
}

获取this.props.code为undefined
<Text style={styles.text}>
条码{this.props.code}
</Text>
...全文
275 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
cwcwj3069 2017-06-29
  • 打赏
  • 举报
回复
react native navigator.push传递参数,第二个界面接收不到

790

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 其他移动相关
社区管理员
  • 移动开发其他问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧