我正在尝试从A.class检索数据到B.claa。 当我在A级直接制作一个按钮时。 来自A的数据可以检索到B类中以显示。
然而,当我使用for循环创建按钮的功能时, 数据实际上不会被检索。它只是未定义..
这里有A班和B班。 所以基本上,在A级,有5个按钮链接到B级的屏幕 B屏幕应该从A获取数据以显示在其屏幕上。
请让我知道这个解决方案..
A类。
const renderButtons = (navigateG) => {
const views = [];
const Name= ["AB","BC","cd","ef","gg"]
for ( var i =0; i<5; i++){
views.push(
<Button
key={i}
onPress={() => navigateG('B', {
Title:"hi",
Name:Name[i],
})}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>);
} // % buttons are created.
return views;
}
export default class A extends Component {
static navigationOptions = ({ navigation }) => ({
title: 'A',
headerLeft: <MenuButton navigation={navigation}/>
});
render() {
const { navigate } = this.props.navigation;
return (
renderButtons(navigate) )
}
</ScrollView>
);
}
}
B班。
export default class B extends Component {
static navigationOptions = ({ navigation }) => ({
title: `${navigation.state.params.Title}`
});
render(){return( <Text>{ this.props.navigation.state.params.Name }</Text> )}
答案 0 :(得分:0)
您可以使用this.props.navigation.state.params.Name
而不是this.props.navigation.state.Name