react-native - React Native 导航参数没有得到更新的值
问题描述
我有一个 React Native 应用程序,我从一个组件获取输入并将输入值作为导航参数发送到根据这些输入数据执行搜索的其他组件。现在,当我第一次navigation.getParam
使用navigation.getParam
. 这是我接受输入的地方:
inputData = () => {
let bodyData = {
customer_id: this.state.customerId,
security_code: this.state.userSecurityCode,
vendor: this.state.vendor,
category_id: this.state.categoryName,
country_id: this.state.countryName,
zone_id: this.state.zoneName,
navigationIdentity: 1
}
this.props.navigation.navigate('Vendor',bodyData)
}
这是我收到的:
componentWillMount() {
const { navigation } = this.props;
this.focusListener = navigation.addListener("didFocus", () => {
const customer_id = navigation.getParam('customer_id')
const security_code = navigation.getParam('security_code')
const vendor = navigation.getParam('vendor')
const category_id = navigation.getParam('category_id')
const country_id = navigation.getParam('country_id')
const zone_id = navigation.getParam('zone_id')
let searchBody = {
customer_id: customer_id,
security_code: security_code,
vendor: vendor,
category_id: category_id,
country_id: country_id,
zone_id: zone_id
}
console.log('in focus',searchBody)
});
}
现在console.log
这里只显示接收到的第一个输入值navigation.getParam
。之后,当我更新输入值并导航时,它仍然显示第一个获取的值。
解决方案
希望这有效
inputData = () => {
let bodyData = {
customer_id: this.state.customerId,
security_code: this.state.userSecurityCode,
vendor: this.state.vendor,
category_id: this.state.categoryName,
country_id: this.state.countryName,
zone_id: this.state.zoneName,
navigationIdentity: 1
}
this.props.navigation.push('Vendor',bodyData)
}
componentWillMount() {
const { params } = this.props.navigation.state;
this.focusListener = this.props.navigation.addListener("didFocus", () => {
const customer_id = params.customer_id;
const security_code = params.security_code;
const vendor = params.vendor;
const category_id = params.category_id;
const country_id = params.country_id;
const zone_id = params.zone_id;
let searchBody = {
customer_id: customer_id,
security_code: security_code,
vendor: vendor,
category_id: category_id,
country_id: country_id,
zone_id: zone_id
}
console.log('in focus',searchBody)
});
}
推荐阅读
- c# - 在asp.net framework 4.0中,如何在没有nuget的情况下实现Stripe PaymentGateway?
- mysql - SQL 更新来自 select 的记录列表
- android - 如何在 RecyclerView 之间添加 Facebook Audience Network 原生广告
- python - 使用 Python 制作包含 100 多个绘图的 PDF 报告的最佳方法是什么?
- android - 在android中,如何在cardview左上角和右上角圆角设置imageview?
- javascript - 如果月份无效,如何从 DOB 计算年龄?
- javascript - 重试失败的 API 调用到 Angular 中的另一个源
- javascript - 使用纯 JS,我可以检查一个类是否正在使用中?
- css - 透明图像曲线轮廓(不是矩形边框)
- javafx - 使用 JavaFX 检测鼠标事件