【发布时间】:2018-08-13 11:15:17
【问题描述】:
我已成功将我的电子邮件和密码值存储在 ReactNative 的 AsyncStorage 中。
现在,我还可以在应用程序启动时从 AsyncStorage 中获取值。
我现在正在使用Alert.alert() 显示值。
我很困惑如何在我的两个 TextInputs 中设置这些值:
1.电子邮件和 2. 密码。
我对状态有一点了解。使用状态可能是可能的。 但是怎么做呢?
知道如何动态更改或设置TextInput 中的值吗?
谢谢。
编辑
州:
state = {
email: '',
password: '',
register: false,
activity: false,
isRemember:false,
}
componentWillMount(){
//To handle Remember Me :
this._checkForRememberMe();
}
登录成功:
this._storeRememberME();
_storeRememberME=async()=>{
//SAVING ASYNCSTORAGE VALUE FOR REMEMBER ME :
Alert.alert("is Remember state >>"+this.state.isRemember);
if(this.state.isRemember){
await AsyncStorage.setItem('username', this.state.email);
await AsyncStorage.setItem('password', this.state.password);
Alert.alert("is Remember state inside >>"+this.state.isRemember);
await AsyncStorage.setItem('isRemember', 'yes');
}else{
const isRemember =AsyncStorage.getItem('rememberMe');
if(isRemember){
Alert.alert("Async clear "+this.state.isRemember);
await AsyncStorage.clear();
}
}
}
// Fetch the token from storage then navigate to our appropriate place
_checkForRememberMe = async () => {
const isRemember = await AsyncStorage.getItem('isRemember');
if(isRemember){
const username = await AsyncStorage.getItem('username');
const password = await AsyncStorage.getItem('password');
this.state.email=username;
this.state.password=password;
this.state.checkedRemember=true;
Alert.alert(""+this.state.email+""+this.state.password);
}else{
this.state.checkedRemember=false;
}
}
_handleCheck(val) {
if(val){
this.state.isRemember=true;
}else{
this.state.isRemember=false;
}
Alert.alert("is remember", ">>>"+val);
}
复选框如下:
<Checkbox
onChange={(val) => this._handleCheck(val)}
style={{marginRight:8}}
checked={checkedRemember}
checkedColor={$primaryBlue}
uncheckedColor={$lightGray}
iconName='matMix'
/>
【问题讨论】:
标签: react-native react-native-android react-native-ios textinput asyncstorage