Reactjs 从第二个导航将本机传递数据反应到父导航
以下是第二屏的部分代码:Reactjs 从第二个导航将本机传递数据反应到父导航,reactjs,react-native,Reactjs,React Native,以下是第二屏的部分代码: state = { hasCameraPermission: null, barcodeValue : "" } FunctionToOpenFirstActivity = () => { this.props.navigation.navigate('First', { barcodeValue: this.state.barcodeValue }); } //after
state = {
hasCameraPermission: null,
barcodeValue : ""
}
FunctionToOpenFirstActivity = () =>
{
this.props.navigation.navigate('First', { barcodeValue: this.state.barcodeValue });
}
//after barcode was scanned
handleBarCodeScanned = ({ type, data }) => {
this.state.barcodeValue = data;
alert(this.state.barcodeValue);
this.FunctionToOpenFirstActivity();
}
下面是render()中父屏幕代码的一部分
条码值
{this.props.barcodeValue}
this.props.barcodeValue为空,有人知道问题出在哪里吗?正如您在文档中可以找到的那样,您可以使用this.props.navigation.getParam(paramName,defaultValue),
defaultValue
读取从上一个视图传递的参数
在您的情况下,尝试将
this.props.barcodeValue
更改为this.props.navigation.getParam('barcodeValue')
正如您可以在文档中找到的那样,您可以使用this.props.navigation.getParam(paramName,defaultValue)
读取从上一个视图传递的参数,defaultValue
是可选的
在您的情况下,请尝试将
this.props.barcodeValue
更改为this.props.navigation.getParam('barcodeValue')
尝试将this.props.barcodeValue
更改为this.props.navigation.getParam('barcodeValue')
@janotama,谢谢,它可以工作。我阅读了stackoverflow的几乎所有相关线程,但甚至没有看到像“getParam”这样的东西。您可以添加答案好的,我很高兴works尝试将this.props.barcodeValue
更改为this.props.navigation.getParam('barcodeValue')
@janotama,谢谢,它可以工作。我阅读了stackoverflow的几乎所有相关线程,但甚至没有看到像“getParam”这样的东西。你可以加上一个答案好吧,我很高兴这行得通
<View style={styles.firstrow}>
<View style={styles.inputWrap}>
<Text style={styles.label}>Barcode Value</Text>
<TextInput style={styles.input}>{this.props.barcodeValue}</TextInput>
</View>
</View>