我不知道我在做什么错,但我有我的组件内的几个功能。但是,我无法将其中的某个功能作为道具传递,因此我收到了this.nextScene
不是函数。不知道我在做什么错 - 获取不是功能错误
下面是从我的组件片段,我已经注释掉那里我遇到的问题:
nextScene() {
this.refs.navigator.push('browse');
}
renderNavigationView() {
return (
<View style={styles.drawer}>
<Touchable
onPress={this.nextScene()} //issue here, "this.nextScene is not a function"
>
<View style={styles.container}>
<Text style={styles.title}>Browse</Text>
</View>
</Touchable>
<Touchable>
<View style={styles.container}>
<Text style={styles.title}>Button</Text>
</View>
</Touchable>
</View>
);
}
render() {
return (
<DrawerLayoutAndroid
ref="drawer"
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
renderNavigationView={this.renderNavigationView}>
<Navigator
ref="navigator"
configureScene={(route) => {
if (Platform.OS === 'android') {
return Navigator.SceneConfigs.FloatFromBottomAndroid;
}
} }
initialRoute={{}}
renderScene={this.renderScene}
/>
</DrawerLayoutAndroid>
);
}
谢谢!
我想你想传递的参考,而不是调用 - 你也可能需要结合本或使用箭头功能,因为'this'并不像它的窗口 – Li357
嗨正确的上下文。所以,如果我尝试'this.nextScene.bind(this)',我得到一个'不能读取属性'绑定'的undefined':( – user1354934