消息关闭
    暂无新消息!
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>

3个回答