Ionic angular firebase bring all the data of a collection

0

I appeal to your help, because I do not know how to solve this. this is the structure of my collection

I need to bring the data: name, description and photo of each one. in my provider I was doing it this way

and then, I was calling the function

The maximum I could get was to get this:

but obviously, when wanting to show that data, it does not show me anything:

If someone can help me, I would appreciate it! I do not know how to do anymore

    
asked by Jacqueline Stella 04.08.2018 в 23:09
source

1 answer

0

The best thing you can do is to fix the structure of your database so as not to nest the information so much.

But if your structure HAS to be like that for reasons of strength, then here is your solution:

In your structure you have something like: /perdida/{codigo}/{numero}/ and there is the data you want.

With your current code, what you are taking out is up to codigo , that is, your data is still below numero . You need a for(key in object) more.

this.afDB.database.ref('perdida').orderByChild('uid').once('value', snapshot => {
    let catData = snapshot.val();
    let temparr = [];
    for (var key in catData) {
      for (var key2 in catData[key]) { // <= for nuevo
        temparr.push(catData[key][key2]) // <= Extrayendo la data
      }
    }
    resolve(temparr);
})

That for new is to enter a node below. There is the data you want.

Just in case, here I leave a StackBlitz running .

    
answered by 05.08.2018 / 23:56
source