javascript - 重定向到子/大子页面后如何继续执行父函数 - React Native
问题描述
我是 React Native 的新手,在 JS 方面也不是很强大,所以请在这种情况下帮助我并帮助我。
我有一个页面 A。当点击一个开关时,它会触发一些功能,比如说
父页面 A - enableInsurance
function switch(insuredID){
if (noCreditCard){
navigator.navigate('paymentPage',{navigateKey:"ObjectsDetailPage"}); //Takes user to payment page to choose payment mode
}
/* On re-navigation after adding CreditCard I need to continue doing below lines */
object.isInsured = true;
const { updateAction } = this.props;
updateAction();
this.setState({ showFlatrateText: false });
}
在我们的场景中,没有信用卡,因此用户被导航到paymentPage,他可以在其中选择支付方式,如 Card、paytm 等。
goToPaymentWebview = (Type) => {
NetInfo.fetch()
.then(resp => {
if(resp.isConnected){
this.setState({showNetDownModal:false});
NavigationService.navigate('paymentWebview',{navigateTo: this.props.navigation.getParam('navigateKey'));
} else {
this.setState({showNetDownModal:true});
}
});
}
选择模式后,用户将被带到大型子页面 - paymentWebview并加载到 webview 中。
用户填写详细信息并提交后,我会在 webview 中详细信息提交的成功或失败回调将用户导航回父页面 A ,如下所示
大子页面 - paymentWebview
if(respJSON.status === 'success') {
const { navigate } = this.props.navigation;
setTimeout(() => {
switch(this.state.navigateTo){
case "ObjectsDetailPage":
navigate('enableInsurance');
break;
case "ObjectPage":
navigate('ObjectPageScreen');
break;
default:
navigate('Second',{ccUpdate: respJSON});
}
}, 2000);
}
现在我回到了使用navigateKey参数重定向到支付页面的页面,在我们的例子中是它的父页面 A - enableInsurance
但是在导航回到这里之后,我如何执行相同的功能 switch(insuredID){ ... } 并继续使用该功能
- 反应原生 0.63.4,
- 反应导航 4.x,
为 iOS 和 Android 创建应用程序,导航使用 Stacknavigator ,没有标签导航。
解决方案
推荐阅读
- javascript - JavaScript 无法始终如一地执行 (V8)
- sql-server - SQL Server 元数据 NVarChar 大小
- airflow - 气流动态任务创建流设置不起作用
- python - 如何将 2D Numpy 数组的按行值组合成一列
- javascript - 在 evaluateOnNewDocument 中更改元素的样式
- apache - Apache ProxyPass 超时 300 秒,但为什么呢?
- javascript - 提交按钮更改禁用属性
- opencv3.0 - 如何在 OpenCV 上进行选择性高斯模糊?
- sql - 序号 1 中的字段为空 返回序号 2 中的字段
- xelatex - 带有 xelatex 的 Latexmk:xdvipdfmx 无法将生成的 xdv 文件转换为 pdf