[Vuejs]-Vue-Firebase: Collect all the keys from firebase entries in script

0๐Ÿ‘

โœ…

Iโ€™m not a VueFire expert, but can help explain some of the Firebase bits. Your this.$firebaseRefs.TeamArray is a Firebase database reference: a reference to a location in the database. It does not actually have any of the data yet, which is why your loop over the reference fails.

To get the data from a database reference, you attach a listener. The simplest way to do this is with once(), which reads the data once:

this.$firebaseRefs.TeamArray.once("value", function(snapshot) {
  snapshot.forEach(function(child){
    team_key_list.push(child.key);
  });
  console.log(team_key_list);
});

There may be some mistakes in this code, but mostly it is just basic Firebase JavaScript SDK (docs) and then glancing at the relevant VueFire code and Vue.js code.

Leave a comment