所以我想将我的数据从JS应用程序中的数组移到Firebase中,以便我可以轻松地更新值,但是我在获取值以完全返回静态状态时遇到问题。由于我要遍历每个,因此它必须是相同的players。我敢肯定,我缺少一些简单的东西,但是任何见解将不胜感激。
这就是我构造静态数组的方式:
// Team names and player IDs for each go here
const staticTeams = [
{
name: 'Byron',
players: ["192", "278", "176", "172", "37", "335"]
},
//etc
];
这就是我获取Firebase数据的方式:
async function getTeams(){
let teams = []
db.collection("teams").get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
// doc.data() is never undefined for query doc snapshots
let data = doc.data();
teams.push(data)
// console.log(doc.id, " => ", doc.data());
});
});
return teams
};
我正在通过打印到另一个功能内的控制台进行测试,如下所示:
console.log("firebase", teams)
console.log("static", staticTeams)
控制台输出如下:
firebase
[]
0: {name: "Mick", players: Array(6)}
1: {name: "Scott", players: Array(6)}
2: {name: "Moir", players: Array(6)}
3: {name: "Boyd", players: Array(6)}
4: {name: "Trev", players: Array(6)}
5: {name: "Tex", players: Array(6)}
6: {name: "Cail", players: Array(6)}
7: {name: "Byron", players: Array(6)}
length: 8
__proto__: Array(0)
static
(8) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {name: "Byron", players: Array(6)}
1: {name: "Moir", players: Array(6)}
2: {name: "Cail", players: Array(6)}
3: {name: "Boyd", players: Array(6)}
4: {name: "Mick", players: Array(6)}
5: {name: "Tex", players: Array(6)}
6: {name: "Trev", players: Array(6)}
7: {name: "Scott", players: Array(6)}
length: 8
__proto__: Array(0)
相关分类