mXX
mXX

Reputation: 3625

Retrieving data from firebase while sorting it correctly

I have this structure in my firebase database

"metadata" : {
    "2017" : {
      "Februari" : {
        "-Kc3BF0V1iLgtnI65LuR" : {
          "date" : "2017-02-03T13:36:38.311Z",
          "price" : 90
        },
        "-Kc3BF0V1xxfrtnI65OlS" : {
          "date" : "2017-02-03T13:36:38.311Z",
          "price" : 90
        }
      },
      "Januari" : {
        "-Kc3E5bpxpo3RpSHH3fn" : {
          "date" : "2017-01-11T13:50:12.264Z",
          "price" : 45
        }
      }
    }
  }

What I am trying to achieve in my app is to show a list like this

> Januari
>   - 45 (=price)
> 
> Februari
>   - 90 ()
>   - 240

The thing is I am able to show the months, but I can't reach the children because of the unique ID created by firebase.

This is the object I am getting back from firebase

e{
    $$conf: Object
    $id: "2017"
    $priority: null
    Februari: Object
        -Kc3BF0V1iLgtnI65LuR: Object
        date: "2017-02-03T13:36:38.311Z"
        price: 90
    Januari: Object
        -Kc3E5bpxpo3RpSHH3fn: Object
        date: "2017-01-11T13:50:12.264Z"
        price: 45
}

How would I approach this?

Upvotes: 0

Views: 64

Answers (1)

Mathew Berg
Mathew Berg

Reputation: 28750

Are you trying to use an ng-repeat? Would something like this work for you:

<div ng-repeat="(name, month) in months">
    {{ name }}
    <div ng-repeat="entry in month">
        {{ entry.price }}
    </div>
</div>

Where months is the result from database.ref().child('metaData').child('2017');

Upvotes: 1

Related Questions