Retrieving data from firebase while sorting it correctly

ⅰ亾dé卋堺 提交于 2020-01-07 02:29:14

问题


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?


回答1:


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');



来源:https://stackoverflow.com/questions/42026092/retrieving-data-from-firebase-while-sorting-it-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!