动态排序 firebase 的结果

order result of firebase dynamically

我是 angular 和 firebase 的新手,我想动态排序我获取的参赛者列表(三向绑定)。

应用程序:https://shining-torch-1269.firebaseapp.com/#/看到它没有被订购!

从 firebase 获取数据的服务代码:

app.service('ContestantsService', function ($firebaseArray, FIREBASE_URI) {
    var service = this;
    var ref = new Firebase(FIREBASE_URI);
    var contestants = $firebaseArray(ref);

    service.getContestants = function () {
        return contestants;
    };

    service.addContestant = function (contestant) {
        contestants.$add(contestant);
    };

    service.updateContestant = function (contestant) {
        contestants.$save(contestant);
    };

    service.removeContestant = function (contestant) {
        contestants.$remove(contestant);
    };
});

方法我已经试过了var contestants = $firebaseArray(ref).orderBy('score')

有没有办法像上面 link 中那样对列表进行排序?

我找到了解决方案..这是代码中的解决方案
我基本上是一些部分,这里是问题的 4 步解决方案。

1 orderByChild

var query = ref.orderByChild('score').limitToLast(10); // added this one
var contestants = $firebaseArray(query);

2 条 FIREBASE 规则

{
"rules": {
    ".read": true,
    ".write": true,
    ".indexOn":"score",
    "score": {
      ".indexOn": ".value"
    }
}
}

3 angular 储备过滤器

app.filter('reverse', function() {
  return function(items) {
    return items.slice().reverse();
  };
});

4 在视图中使用过滤器

<tr ng-repeat="contestant in main.contestants | reverse ">