【发布时间】:2018-01-17 02:15:52
【问题描述】:
当我单击子组件中的按钮时,我无法在父组件上触发方法。
这是我的代码:
constructor(props) {
super(props);
this.state = {
text: '',
};
}
nav = DrawerNavigator({
Child: {
screen: Child,
navigationOptions: {
title: 'Child Component'
}
},
Profile: {
screen: Profile
},
}, {
screen: Profile,
contentComponent: DrawerContent
});
const DrawerContent = (props) => (
<View> {this.state.text}</View>
})
const
nav2= DrawerNavigator({
Child: {
screen: Child,
navigationOptions: {
title: 'Child cmp'
}
},
Profile: {
screen: Profile
},
screen: Manager
}
}, {
screen: Profile,
contentComponent: DrawerContent
});
const Layout = createRootNavigator(signedIn);
return (
<View>
<Layout/>
</View>
);
我希望当单击子 cmp 上的按钮时,我正在调用子 cmp 中的一个函数,该函数在该调用完成后执行一些后端调用,我希望更新父状态。我尝试了不同的方法,但我无法成功!
【问题讨论】:
-
如果您向我们展示您尝试过的具体代码以及结果如何,您更有可能获得帮助。询问“我该怎么做 X”的问题被认为是 StackOverflow 的题外话。
标签: javascript reactjs react-native react-router react-redux