我在 Firebase 中有一个数组,我得到的结果如下:
var ref = new Firebase(url);
ref.orderByChild("date").on("child_added", function(obj) {
console.log(obj.val());
});
但我需要按降序排列。我如何使用 Firebase 做到这一点?
谢谢!
最佳答案
由于您添加了 AngularJS 标签,我假设您在项目中使用 Angular。在这种情况下,使用 AngularFire (http://angularfire.com) 会让您的生活变得更加轻松。
使用 AngularFire 后,您可以使用 $firebaseArray
服务从数据库中获取数组,并像对任何其他数组一样对其进行排序。
$firebaseArray
文档可以在这里找到:https://www.firebase.com/docs/web/libraries/angular/guide/synchronized-arrays.html
关于javascript - Firebase 顺序按降序排列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32528504/