显示收藏品的所有文档React Firebase
我有一个名为“ journee”的集合,我想构建一个包含所有元素的列表,因此我得到了所有数据:
export async function getAllJournaux() {
const journaux = {};
const querySnapshot = await getDocs(collection(db, "journaux"));
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
// console.log(doc.id, " => ", doc.data());
journaux[doc.id] = doc.data();
});
return journaux;
}
然后在我的页面上getit witn a persefect,例如:
const [journaux,setJournaux] = react.estate.usestate(useestate)( );
useEffect(() => {
const getJournaux = async () => {
try {
const getJournaux = await getAllJournaux();
setJournaux(getJournaux);
} catch(error) {
// handle any rejections/errors/etc
}
};
getJournaux(); // <-- fetch/compute coupeur value
}, []);
if (!journaux){
console.log("wait"); // or loading indicator/etc
}else{
console.log(journaux);
}
但是,如何使用Console.Log访问屏幕上的数据列表。
控制台的支出。log
{
"8SlEz4CslmTMSxWuqB8W2lDICwj22022-05-02": {
"date": "2022-05-02",
"billetage": {
"5": 0,
"10": 0,
"25": 0,
"50": 0,
"100": 0,
"200": 0,
"250": 0,
"500": 0,
"1000": "2",
"2000": "3",
"5000": "4",
"10000": "5"
},
"pt": "3400000",
"at": "30000",
"vt": "450000",
"coupeur": "qKh2entwU7YD0wcxWRI3"
},
"8SlEz4CslmTMSxWuqB8W2lDICwj22022-05-03": {
"at": "555",
"date": "2022-05-03",
"coupeur": "YuYRYzWj4CVidsmAjO1d",
"vt": "334",
"pt": "5555"
},
"KiuU1xQaKWTAx5mt9XL8vBpY3Y822022-03-01": {
"pt": "150000",
"vt": "450000",
"date": "2022-03-01",
"at": "3000",
"billetage": {
"5": "5",
"10": "3",
"25": "5",
"50": "1",
"100": "2",
"200": "4",
"250": "2",
"500": "3",
"1000": "6",
"2000": "3",
"5000": "4",
"10000": "2"
},
"coupeur": "Ad5g5AE2HdqbZGzhu7G5"
},
"KiuU1xQaKWTAx5mt9XL8vBpY3Y822022-05-11": {
"coupeur": "qKh2entwU7YD0wcxWRI3",
"billetage": {
"5": 0,
"10": 0,
"25": 0,
"50": 0,
"100": 0,
"200": 0,
"250": 0,
"500": 0,
"1000": 0,
"2000": "5",
"5000": "3",
"10000": "10"
},
"pt": "30000",
"date": "2022-05-11",
"at": "100",
"vt": "200000"
},
"KiuU1xQaKWTAx5mt9XL8vBpY3Y822022-05-23T14:03": {
"date": "2022-05-23T14:03",
"pt": "50000",
"coupeur": "",
"at": "130000",
"vt": "200000",
"billetage": {
"5": 0,
"10": 0,
"25": 0,
"50": 0,
"100": 0,
"200": 0,
"250": 0,
"500": 0,
"1000": 0,
"2000": "3",
"5000": "5",
"10000": "2"
}
}
}
谢谢
I have a collection named "journee", and i want to build a list with all elements inside so i get all the data like this :
export async function getAllJournaux() {
const journaux = {};
const querySnapshot = await getDocs(collection(db, "journaux"));
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
// console.log(doc.id, " => ", doc.data());
journaux[doc.id] = doc.data();
});
return journaux;
}
Then on my page getIt witn an useEffect like :
const [journaux, setJournaux] = React.useState();
useEffect(() => {
const getJournaux = async () => {
try {
const getJournaux = await getAllJournaux();
setJournaux(getJournaux);
} catch(error) {
// handle any rejections/errors/etc
}
};
getJournaux(); // <-- fetch/compute coupeur value
}, []);
if (!journaux){
console.log("wait"); // or loading indicator/etc
}else{
console.log(journaux);
}
But how to make a list with the data on my screen , for the moment i just access it with console.log.
The outpout of console.log
{
"8SlEz4CslmTMSxWuqB8W2lDICwj22022-05-02": {
"date": "2022-05-02",
"billetage": {
"5": 0,
"10": 0,
"25": 0,
"50": 0,
"100": 0,
"200": 0,
"250": 0,
"500": 0,
"1000": "2",
"2000": "3",
"5000": "4",
"10000": "5"
},
"pt": "3400000",
"at": "30000",
"vt": "450000",
"coupeur": "qKh2entwU7YD0wcxWRI3"
},
"8SlEz4CslmTMSxWuqB8W2lDICwj22022-05-03": {
"at": "555",
"date": "2022-05-03",
"coupeur": "YuYRYzWj4CVidsmAjO1d",
"vt": "334",
"pt": "5555"
},
"KiuU1xQaKWTAx5mt9XL8vBpY3Y822022-03-01": {
"pt": "150000",
"vt": "450000",
"date": "2022-03-01",
"at": "3000",
"billetage": {
"5": "5",
"10": "3",
"25": "5",
"50": "1",
"100": "2",
"200": "4",
"250": "2",
"500": "3",
"1000": "6",
"2000": "3",
"5000": "4",
"10000": "2"
},
"coupeur": "Ad5g5AE2HdqbZGzhu7G5"
},
"KiuU1xQaKWTAx5mt9XL8vBpY3Y822022-05-11": {
"coupeur": "qKh2entwU7YD0wcxWRI3",
"billetage": {
"5": 0,
"10": 0,
"25": 0,
"50": 0,
"100": 0,
"200": 0,
"250": 0,
"500": 0,
"1000": 0,
"2000": "5",
"5000": "3",
"10000": "10"
},
"pt": "30000",
"date": "2022-05-11",
"at": "100",
"vt": "200000"
},
"KiuU1xQaKWTAx5mt9XL8vBpY3Y822022-05-23T14:03": {
"date": "2022-05-23T14:03",
"pt": "50000",
"coupeur": "",
"at": "130000",
"vt": "200000",
"billetage": {
"5": 0,
"10": 0,
"25": 0,
"50": 0,
"100": 0,
"200": 0,
"250": 0,
"500": 0,
"1000": 0,
"2000": "3",
"5000": "5",
"10000": "2"
}
}
}
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
getalljournaux正在返回对象,因此您必须使用对象。
getAllJournaux is returning an object, so you have to use Object.keys to iterate