【发布时间】:2016-03-04 09:16:41
【问题描述】:
我是 React-Native 的新手,我正在尝试使用
如果你看下面的代码 MyApp 类是我的应用程序的入口点,在渲染函数中它有一个包含
我感觉可能是 ES6 导致了我的问题。
class MyApp extends Component {
constructor(props) {
super(props);
}
// I want to access navigator in this function
onActionSelected(position) {
if (position === 0) { // index
this.props.navigator.push({
name: 'FeedView',
component: FeedView
});
}
}
render() {
return (
<View style={styles.container}>
<ToolbarAndroid
title="MyApp"
style={styles.toolbar}
actions={toolbarActions}
onActionSelected={this.onPressFeed.bind(this)}
navigator={this.props.navigator}>
</ToolbarAndroid>
<Navigator
initialRoute={{name: 'WelcomeView', component: WelcomeView}}
configureScene={() => {
return Navigator.SceneConfigs.FloatFromRight;
}}
renderScene={(route, navigator) => {
// count the number of func calls
console.log(route, navigator);
if (route.component) {
return React.createElement(route.component, { navigator });
}
}}
/>
</View>
);
}
}
【问题讨论】:
-
尚未对其进行测试,但请尝试参考:facebook.github.io/react/docs/more-about-refs.html e.g.
ref={c => this.navigator = c}
标签: android reactjs react-native