Firebase: How To Get The Data When Child_added Complete
I have a case when I need to fetch all event objects. Each event object has a property city_id which is a relationship key to a single city object from the list with all cities. ..
Solution 1:
The only way to know when loading of the initial data is done is to use a value
event. I haven't really used async
/await
yet, but expect you'll need something like this:
async function getAllEvents() {
const eventsRef = rootRef.child('events');
const eventsArray = [];
await eventsRef.on('value', async (snapshot) => {
snapshot.foreach(function(child) {
const eventObject = child.val();
const cityObject = await getEventCity(eventObject.city_id);
eventObject.city = cityObject;
eventsArray.push(eventObject);
});
});
return eventsArray;
}
Post a Comment for "Firebase: How To Get The Data When Child_added Complete"