我在asyncStorage中有一个名为asyncStorage的表,可以用来保存多个users详细信息(也就是说,多个用户只使用一部手机就可以登录到应用程序中)。
我有过
const users = {
email: this.state.email,
password: this.state.password,
sex: this.state.sex
};然后使用JSON.stringify()保存它
现在,如何检索正确的用户信息?
我正沿着这条路线思考,但由于使用
AsyncStorage
SELECT email, password from users where email===this.state.email and password === this.state.password我也是这样想的,但我肯定做错了。
getStudent = async () => {
//function to get the value from AsyncStorage
let users= await AsyncStorage.getItem('students');
let allUsers= JSON.parse(users);
// Check if entered username and password equals any username and password from the DB
allUsers.filter(function (credentials) {
credentials.email.includes(this.state.email);// Then, I hit the wall here
})
this.props.navigation.navigate('ViewProfile');
};我该怎么做呢?
发布于 2020-10-27 05:51:45
用户必须是数组而不是对象。例如
const users = [
{ email: 'test@test.com', password: '123', sex: 'male'},
{ email: 'test@test.com', password: '123', sex: 'male'}
{ email: 'test@test.com', password: '123', sex: 'male'}
]另一种代码
let user = allUsers.filter(u => u.email === this.state.email)[0];
if (user) {
this.props.navigation.navigate('/viewProfile', { data: user })
} else {
alert ('Not found')
}https://stackoverflow.com/questions/64544971
复制相似问题