【发布时间】:2021-07-10 14:31:08
【问题描述】:
所以基本上我试图实现的是获取每个查询的事件的参与者文档。请查看发布的图像。两者都有一个需要匹配的公共 EventId 字段。下面的代码仅适用于第一次迭代,但立即停止在 getRealtimeChild() 之前。Events 文档有一个 Id 字段
useEffect(() => {
//Fetch events ordered by timestamp
const eventsRef = realDB.ref('Events').orderByChild('EventTimestamp').limitToFirst(3);
setLoader(true);
eventsRef.on('value', (snapshot) => {
//var o = 0;
//var i = 0;
//Fetch Participants of each events
snapshot.forEach(function (events) {
// console.log(events.key)
// console.log('outer =>' ,o+=1)
getRealtimeChild('Participants', 'EventId', events.key).limitToLast(5).get().then(function (snapshot) {
console.log(events.key)
snapshot.forEach(function (p) {
// console.log('p =>',p.key)
// console.log('inner =>' ,i+=1)
participants=[];
participants.push(p.val())
setParticipantList([])
setParticipantList(participants)
// console.log(participants)
// console.log(participantList)
})
eventList.push(Object.assign(events.val(),{id: events.key},{participants:participantList}));
// console.log(participantList)
});
});
setEventsList(eventList)
setLoader(false);
console.log(eventList)
});
}, [])
【问题讨论】:
标签: javascript reactjs firebase firebase-realtime-database