1
当我按下导航栏的右键时,我想调用场景组件中的一个函数。React本地路由器Flux - 如何调用场景的方法
在父:
<Router
style={routerStyle.router}
navigationBarStyle={navBarStyle.navBar}
titleStyle={navBarStyle.navTitle}
leftButtonStyle={navBarStyle.leftButtonStyle}
drawerImage={hamburgerIcon}>
<Scene
key='History'
component={History}
title='History'
type='reset'
rightButtonImage={mailIcon}
onRight={this.sendMail} <-- ON THIS
rightButtonStyle={navBarStyle.rightButtonStyle}
rightButtonIconStyle={navBarStyle.rightButtonIconStyle} />
</Router>
在孩子(History.js):
openModal() {
this.setState({modalVisible: true}); <-- DO THIS
}
closeModal() {
this.setState({modalVisible: false});
}
如何使用Actions.History({modalVisible:true})或Actions.refresh({modalVisible:true}),但是将其设置为prop。然后,你会观察componentWillReceiveProps的变化。 –
它的工作原理!特别是我用 'sendMail(){ Actions.refresh(); }'在我的路由器和 'componentWillReceiveProps(){ this.toggleModal(); } toggleModal(){ this.setState({modalVisible:!this.state.modalVisible}); }' 在场景中,请发布答案,以便我可以接受它:) – Haruspik