React native 如何在.where()中使用veriable-firestorect-Native?
我希望使用veriable in-Where查询从用户集合中访问用户数据。我使用了这段代码,但没有检索到数据:React native 如何在.where()中使用veriable-firestorect-Native?,react-native,where,google-cloud-firestore,React Native,Where,Google Cloud Firestore,我希望使用veriable in-Where查询从用户集合中访问用户数据。我使用了这段代码,但没有检索到数据: export const userAddToOrganization = (email) => { return (dispatch) => { if (email !== '') { console.log('email' , email); //'e@e.com √' firebase.firestore().coll
export const userAddToOrganization = (email) => {
return (dispatch) => {
if (email !== '') {
console.log('email' , email); //'e@e.com √'
firebase.firestore().collection('users').where("email", '==', `${email}`)
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc.id, "=>", doc.data());
});
});
}
};
};
当我使用as时e@e.com“,成功检索到数据。但我想使用veriable(电子邮件)
如何在WHERE查询中使用veriable获取数据。
多谢各位
export const userAddToOrganization = (email) => {
return (dispatch) => {
if (email !== '') {
console.log('email' , email); //'e@e.com √'
const ref = firebase.firestore().collection('users')
ref.where("email", '==', email)
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc.id, "=>", doc.data());
});
});
}
};
};
我还没有测试过它,但我看不出它为什么不工作。删除字符串文字并直接传递电子邮件。如果这不起作用,那么我想应该是修剪字符串,这样会删除所有额外的空间
export const userAddToOrganization = (email) => {
return (dispatch) => {
if (email !== '') {
console.log('email' , email); //'e@e.com √'
const ref = firebase.firestore().collection('users')
ref.where("email", '==', email.trim())
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc.id, "=>", doc.data());
});
});
}
};
};
我更新了我的答案,尝试一下,让我知道它是如何进行的@GökhanGeyikI尝试了更新后的答案,但未成功:(我有一个错误:无法读取属性trim(),请使用第一个答案,但不使用trim()…我有完全相同的,它对我有效。@GökhanGeyiki认为问题在于电子邮件不是字符串而是对象。因为我将电子邮件发送给actions作为this.props。我将其更改为this.props.email,然后问题解决了。非常感谢
export const userAddToOrganization = (email) => {
return (dispatch) => {
if (email !== '') {
console.log('email' , email); //'e@e.com √'
const ref = firebase.firestore().collection('users')
ref.where("email", '==', email.trim())
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc.id, "=>", doc.data());
});
});
}
};
};