我对React native很陌生。我想在一个屏幕上设置包括“添加”,“编辑”和“显示详细信息”在内的信息,因此我为每个事件在调用时设置状态。
添加时,设置为isAdding,编辑时,设置为isEditing,当显示详细信息时,设置isShowDetail并进行导航,就像这样。
屏幕A:
this.props.navigation.navigate(ROUTE_INVOICE_DETAIL_NAME, { invoice, isEditing: true });
和屏幕B(详细信息):
constructor(props) {
super(props);
this.isShowDetail = props.navigation.getParam("isShowDetail");
console.log(this.isShowDetail);
this.isAdding = props.navigation.getParam("isAdding")
this.isEditing = props.navigation.getParam("isEditing");
const { params = {} } = this.props.navigation.state;
const { invoice = {} } = params;
const { paid = 0, incurred = 0, transportFee = 0, id} = invoice;
this.state = {
id,
invoice,
isShowTicketDetail: false,
customer: {},
paid,
incurred,
transportFee,
details: {},
};
我不知道如何获取isEditing
和isAdding
的值,它返回未定义的值。
ROUTE_INVOICE_DETAIL_NAME
已声明,我敢肯定它会进入详细信息。
答案 0 :(得分:0)
在屏幕A:
this.props.navigation.navigate(ROUTE_INVOICE_DETAIL_NAME, {
invoice_data: invoice ,
isEditing: true
})
在屏幕B上,您可以获取如下数据:
let invoice_data = this.props.navigation.state.params.invoice_data
let isEditing = this.props.navigation.state.params.isEditing