Angularjs 在正确排序的同时从firebase检索数据
我的firebase数据库中有这个结构Angularjs 在正确排序的同时从firebase检索数据,angularjs,firebase,firebase-realtime-database,angularfire,Angularjs,Firebase,Firebase Realtime Database,Angularfire,我的firebase数据库中有这个结构 "metadata" : { "2017" : { "Februari" : { "-Kc3BF0V1iLgtnI65LuR" : { "date" : "2017-02-03T13:36:38.311Z", "price" : 90 }, "-Kc3BF0V1xxfrtnI65OlS" : { "date" : "2017-02
"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
}
}
}
}
我试图在我的应用程序中实现的是显示这样的列表
> Januari
> - 45 (=price)
>
> Februari
> - 90 ()
> - 240
问题是我可以显示月份,但我无法联系到孩子们,因为firebase创建的唯一ID
这就是我从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
}
我将如何处理此问题?您是否尝试使用ng repeat?您是否希望这项工作:
<div ng-repeat="(name, month) in months">
{{ name }}
<div ng-repeat="entry in month">
{{ entry.price }}
</div>
</div>
{{name}}
{{entry.price}}
其中月份是来自
database.ref().child('metaData').child('2017')的结果代码>如何在没有firebase创建的唯一密钥的情况下输入childNode?这实际上是我的问题:)你为什么不找回整个月和所有的孩子呢。将它们推到一个数组中,并按以下方式对其childs进行排序:allChilds.sort((a,b)=>a.price>b.price);这对我起了作用。但是你能告诉我{{entry.price}}
是如何工作的吗?我在哪里用firebase创建的唯一键输入了对象,比如-Kc3BF0V1iLgtnI65LuR
它只是在一个对象上循环,您可以在月份内完成ng repeat=“(键,条目)”
,然后也拥有该键