javascript - 如何在数组中获取我的 documentSnapshot?
问题描述
我想连接 2 个数组。
第一个应该在我的 this.state.TeamOthers
querySnapshot.forEach(async (doc) => {
let id = doc.id;
firestore()
.collection("Teams")
.doc(id)
.collection("membersList")
.where("id", "==", await AsyncStorage.getItem("userID"))
.get()
.then((querySnapshot) => {
if (querySnapshot.empty) {
console.log("no doc found");
} else {
querySnapshot.forEach(async (docMember) => {
let valid = docMember._data;
console.log("validé", valid);
firestore()
.collection("Teams")
.doc(id)
.collection("membersList")
.where("statut", "==", "Validé")
.get()
.then((querySnapshot) => {
if (querySnapshot.empty) {
console.log("no validate profile");
} else {
querySnapshot.forEach((valide) => {
let TeamsMem = valide._data;
firestore()
.collection("Teams")
.get()
.then((documentSnapshot) => {
if (documentSnapshot.exists) {
let TeamsOther = documentSnapshot._data;
console.log(TeamsOther);
this.state.TeamsOthers.push(TeamsOther);
}
return;
});
在我的 console.log(TeamsOthers)上,我明白了:
[2021 年 5 月 18 日星期二 11:20:40.262] LOG {“活动”:“TennisLamb”,“地址”:“尼斯”,“城市”:“尼斯”,“所有者”:true,“成员”:“5” ,“文本”:“coucou toi”,“tokenTeam”:“ohxur2pqkf”,“uid”:“3SGn1EWf9hP2DqU0mExGII2B7hI3”} [2021 年 5 月 18 日星期二 11:20:40.263] LOG {“活动”:“TennisLamb2”,“地址” :“Nice”,“City”:“Nice”,“Owner”:true,“members”:“5”,“text”:“coucou toi”,“tokenTeam”:“lc8u2d88io7”,“uid”:“3SGn1EWf9hP2DqU0mExGII2B7hI3 "}
所以即使我推送我的数据,她也不想出现在一个数组中。
其次,我得到了我的 this.state.TeamsPerso :
firestore()
.collection("Teams")
// Filter results
.where("uid", "==", await AsyncStorage.getItem("userID"))
.get()
.then((querySnapshot) => {
if (querySnapshot.empty) {
console.log("no documents found");
} else {
querySnapshot.forEach(async (doc) => {
let TeamsPerso = doc._data;
this.state.TeamsPerso.push(TeamsPerso);
console.log("TeamsPerso", TeamsPerso);
});
}
});
};
在我的 console.log 上与以前的状态相同:
[2021 年 5 月 18 日星期二 11:20:40.800] LOG TeamsPerso {"Activity": "ping pong", "Adress": "", "City": "Nice", "Owner": true, "members": "" ,“文本”:“”,“tokenTeam”:“h9oh21iq235”,“uid”:“uqb4wvB5LIOD3xxjN8Tr7V6qmM72”}
TeamsPerso {“活动”:“Patin sur glace”,“地址”:“Plage”,“城市”:“Nice”,“所有者”:true,“成员”:“6”,“文本”:“patin sur sable ", "tokenTeam": "stikouajl", "uid": "uqb4wvB5LIOD3xxjN8Tr7V6qmM72"}
然后我想连接所有这些数据,我尝试了几种方法:
let finalTeam = this.state.TeamsPerso.concat(
this.state.TeamsOthers
);
console.log("teamsOthers", finalTeam);
我的结果只是我的 TeamsPerso :
teamsOthers [{"Activity": "ping pong", "Adress": "", "City": "Nice", "Owner": true, "members": "", "text": "", "tokenTeam" :“h9oh21iq235”,“uid”:“uqb4wvB5LIOD3xxjN8Tr7V6qmM72”},{“活动”:“Patin sur glace”,“地址”:“Plage”,“城市”:“尼斯”,“所有者”:true,“成员” :“6”,“文本”:“patin sur sable”,“tokenTeam”:“stikouajl”,“uid”:“uqb4wvB5LIOD3xxjN8Tr7V6qmM72”}]
你知道我如何连接 TeamsPerso 和 TeamsOther 吗?
解决方案
推荐阅读
- c - 如何获取我通过程序调用的 exe 的标准输出?
- reactjs - 无法使用 Amplify Auth.currentAuthenticatedUser 检索用户名
- ios - 如何通过扩展使用一些自定义方法来调整类的方法
- php - 如何根据今天日期显示数据数量
- java - 在Java中比较二维数组元素的最佳方法?
- javascript - 如果初始值是具有大量计算的函数,useState 是否会导致渲染?
- php - 使用 post 方法后没有获取数据并且仍然在 url 中的数据
- c# - 无法使用 Type.GetType(string) 获取 LinkedList`T 的类型
- python - 元素大于三个或更多列表
- forms - .NET Core 部分视图表单不注册外键