2
我有简单的导航传递动态道具阵营本地
if (routeId === 'Page1') {
return (
<Page1
navigator={navigator} />
);
}
if (routeId === 'Page2') {
return (
<Page2
navigator={navigator} />
);
}
然后在一个页面上就行了我的功能结合到每一行,对象通过。 (c)
render(){
this.state.listData.map((c, i) => {
return <TouchableOpacity onPress={this.visitPage.bind(this, c)} key={ i } style={ styles.cContainer }>
<Image source={{uri:c.avatar}} style={ styles.circular }>
</Image>
<Text style={styles.text}>{c.name}</Text>
</TouchableOpacity>
}
}
现在我怎么能得到这个对象去第2页? 在visitPage我有...
visitPage(){
this.props.navigator.push({
id:'Page2',
name:'Page2',
passProps:{data:this} //iOS only uses passProps??
});
}
香港专业教育学院还试图
visitPage(){
this.props.navigator.push({
id:'Page2',
name:'Page2',
data:this
});
}
然后在第2页在构造函数中,我的数据设置为空,页面上安装,读取性能。
constructor(props, context) {
super(props, context);
console.log(this.props);// Returns my navigator object, but no properties along with it.
this.state = {
page2Data: this.props.data,
};
}
onComponentWillMount(){
console.log(this.props.data); // Returns undefined
this.setState({page2Data: this.props.data});
}
谢谢!很简单。我发现文档缺乏与反原生相当困难。也许我只是吮吸阅读它..大声笑 – KyleK
不,这需要被添加到文档肯定! –
请提交PR到文档以帮助那些关注 –