对于如此“onPress = {this.onPressButton.bind(这)}”导致我的应用程序失败?阵营本地未定义不是(评价“this.onPressButton.bind”)的对象
我能做些什么来解决它。我相信它与(这)变得没有束缚或某事有关?
我已经被渲染了一个名为登录组件:
export default class Login extends Component {
constructor(props) {
super(props);
this.state = {
id:'login'
}
}
render() {
return(
<KeyboardAvoidingView behavior="padding" style={style.container}>
<View style={style.logoContainer}>
<StatusBar barStyle="light-content" />
<Image style={style.logo} source={require('../../image/Octocat.png')} />
<Text style={style.logoText}> A Github app using React Native by{"\n"} Thomas Charlesworth</Text>
</View>
<View style={style.formContainer}>
<LoginForm />
</View>
</KeyboardAvoidingView>
);
}
}
和登录表单组件:
export default class LoginForm extends Component {
onPressButton(){
this.props.navigator.push({
id: 'splash',
passProps: {
// Your Props
}
})
}
render() {
return(
<View style={style.container}>
<TextInput
style={style.input}
placeholder="Username"
placeholderTextColor="rgba(255,255,255,0.5)"
returnKeyType="next"
autoCapitalize="none"
autoCorrect={false}
onSubmitEditing={()=> this.passwordInput.focus()}
/>
<TextInput
style={style.input}
secureTextEntry
placeholder="Password"
placeholderTextColor="rgba(255,255,255,0.5)"
returnKeyType="go"
ref={(input) => this.passwordInput = input}
/>
<TouchableOpacity
style={style.buttonContainer}
onPress={this.onPressButton.bind(this)}
>
<Text style={style.buttonText}>
LOGIN
</Text>
</TouchableOpacity>
</View>
);
}
}
您是否定义了此方法'onPressButton' ?? –
我做了一个编辑请参考。我定义了一个方法是。哪些停止错误,但当我点击按钮,我得到:undefined不是一个对象(评估'this.props.navigator.push') –