【问题标题】:Display items in reverse order from Firebase in ng-repeat在 ng-repeat 中以与 Firebase 相反的顺序显示项目
【发布时间】:2015-05-11 11:44:44
【问题描述】:

我的问题类似于下面的 SO 问题

Reverse order of items pulled from database in ng-repeat

但是,我正在使用以下方法来绑定特定 AccountID 的所有交易

var syncObject = $firebaseObject(fb.child("members/" + fbAuth.uid + "/accounts/" + $scope.AccountId));
syncObject.$bindTo($scope, "data");

与上面提到的SO问题和我的不同之处在于我使用$firebaseObject来绑定数据(三向数据绑定)。

那么我怎样才能以相反的顺序显示交易列表呢?我想在视图顶部显示最近的交易

提前感谢您的帮助!

【问题讨论】:

  • 只是一些想法:因为它是一个交易的列表,也许你应该使用firebaseArray而不是firebaseObject。此外,也许this 会有用。
  • 如文档中所述,$firebaseArray 用于绑定集合,而 $firebaseObject 不是。不用 $bindTo 也可以。进行更改并适当使用工具时,只需调用 $save()。

标签: firebase ionic-framework angularfire


【解决方案1】:

在这种情况下,您应该使用 $firebaseArray,因为它可以让您随意排序:

Javascript

var ref = fb.child("members/" + fbAuth.uid + "/accounts/" + $scope.AccountId);

$scope.data = $firebaseArray(ref);

HTML

<div data-ng-repeat="child in data | orderBy:'FIELD_TO_SORT_BY':true>
    <!-- other elements -->
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多