Javascript React Native Undefined不是对象(正在计算'this.refs.'DRAWER'])
如何解决此错误?我已经试过了,但仍然有错误 这是我的代码root.js:Javascript React Native Undefined不是对象(正在计算'this.refs.'DRAWER']),javascript,android,react-native,native-base,Javascript,Android,React Native,Native Base,如何解决此错误?我已经试过了,但仍然有错误 这是我的代码root.js: <DrawerLayoutAndroid drawerWidth={250} drawerPosition={DrawerLayoutAndroid.positions.Left} renderNavigationView={() => navigationView} ref={'DRAWER'}> <Navigator renderSce
<DrawerLayoutAndroid
drawerWidth={250}
drawerPosition={DrawerLayoutAndroid.positions.Left}
renderNavigationView={() => navigationView}
ref={'DRAWER'}>
<Navigator
renderScene={this.renderScene}
initialRoute={{component: Home}}
ref={(nav) => { this.appNav = nav; }} />
</DrawerLayoutAndroid>
}
这可能不在handleMenuPress的范围内。
尝试将handleMenuPress更改为箭头功能
handleMenuPress = () => {
this.refs['DRAWER'].openDrawer();
}
您应该将方法绑定到构造函数中,这是最好的方法
constructor(props){
super(props)
this.handleMenuPress = this.handleMenuPress.bind(this)
}
你能在handleMenuPress中操控'this.refs'吗,看看它是否在iterror中有drawer'无法读取未定义的属性'openDrawer',如何修复这个问题,先生?请检查你是否正确地将ref给了DrawerLayoutAndroid。您可以尝试以下语法ref={drawer=>{this.drawer=drawer;}}},而不是这个.refs['drawer'].openDrawer;使用this.drawer.openDrawer;
handleMenuPress = () => {
this.refs['DRAWER'].openDrawer();
}
constructor(props){
super(props)
this.handleMenuPress = this.handleMenuPress.bind(this)
}