我有两个包含数据的数组,我应该将这些数组传递给另一页。
首页
stopConnection(array_acc_sx,array_acc_dx) {
return new Promise((resolve, reject) => {
console.log("Inizio stopConnection");
Actions.registerattivita(this.state.array_acc_sx,this.state.array_acc_dx)
// ....
});
}
render() {
return (
// ......
<View>
<TouchableOpacity
style={[style.button, style.buttonOK]}
onPress={() =>
this.stopConnection(
this.state.array_acc_sx,
this.state.array_acc_dx
)
}
>
// ....
以及 RegisterAttivita.js :
constructor(props) {
super(props);
this.state = {
loading: true,
array_acc_sx: [],
array_acc_dx: [],
};
}
componentDidMount() {
this.dataReceived(this.props.array_acc_sx,this.props.array_acc_dx)
}
dataReceived(array_acc_sx, array_acc_dx){
console.log("data acc_sx: " + this.props.array_acc_sx)
console.log("data acc_dx: " + this.props.array_acc_dx)
}
所以我应该将this.props.array_acc_sx和this.props.array_acc_dx传递到另一页。目前,我知道这两个变量是[undefined]。
如何通过这两个? 谢谢
答案 0 :(得分:1)
首页
Actions.registerattivita({array_acc_sx:this.state.array_acc_sx,array_acc_dx:this.state.array_acc_dx});
第二页
constructor(props) {
super(props);
this.state = {
loading: true,
array_acc_sx: props.array_acc_sx,
array_acc_dx: props.array_acc_dx
};
}