我在反应本机 NavigatorIOS 中使用 onRightButton。
我希望能够调用驻留在我正在推送的组件中的函数,但我不知道如何实现这一点。
这是代码示例:
this.props.navigator.push({
component: SingleResultView,
title: "SomeTitle",
rightButtonIcon: require('image!mapsmarker'),
passProps: {
userPosition: this.props.userPosition
},
onRightButtonPress: () => { SingleResultView.foo(); } // NOT WORKING!
});
我怎样才能做到这一点?
The ref
回调道具是你的朋友!https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute
goToResults() {
this.props.navigator.push({
component: SingleResultView,
title: "SomeTitle",
rightButtonIcon: require('image!mapsmarker'),
passProps: {
userPosition: this.props.userPosition,
ref: this.onResultsRef,
},
onRightButtonPress: () => { this._resultsView && this._resultsView.foo(); }
});
}
onResultsRef(resultsViewRef) {
this._resultsView = resultsViewRef;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)