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