我想退還密碼和複選框狀態的用戶名&的輸入值。我在Stackoverflow上發現了這個相關問題。但是,當嘗試實現這讓錯誤在React本機中獲取TextInput值和複選框狀態
「空」是不是(評估 「this.state.username」)的對象
誰能幫助我以檢索輸入值和複選框狀態我是新來的陣營本地
代碼:
var CheckBox = require('react-native-checkbox');
var Button = require('react-native-button');
var reactnative = React.createClass({
render: function() {
return (
<View style={styles.container}>
<Text style={styles.signin}>Sign In</Text>
<TextInput style={styles.logininput} ref= "username" onChangeText={(event) => this.setState({username:event.nativeEvent.text})} value={this.state.username}/>
<TextInput style={styles.logininput} value="Password"/>
<CheckBox label='Remeber Me' checked = {false} onClick={this._CheckBoxState}/>
<Button style={styles.loginButton} onPress={this._handlePress.bind(this)}>
Login
</Button>
</View>
);
},
_handlePress(event) {
//Get TextInput value
var username= this.state.username;
alert(username);
},
_CheckBoxState(event){
//want to change the state from true to false or vice-versa
}
});
你在哪裏初始化初始狀態? –