如何对从firebase

时间:2018-04-04 05:01:05

标签: angularjs firebase angularjs-ng-repeat

我是angularJS的新手我从firebase获得键值对如何按timeStamp排序以显示最新的顶部。 请帮我 。提前谢谢,orderBy和反向不工作

var ref = new Firebase("https://firebaseio.com/notifications/");
var fb = $firebase(ref);

var syncArreglo = fb.$asObject();

syncArreglo.$loaded().then(function() {
    angular.forEach(syncArreglo, function (value, key) {
        if(syncArreglo.value != null){
            syncArreglo.value.firebaseKey = syncArreglo.key;
        }
    });
});

syncArreglo.$bindTo($scope,'chats');

<ul class="menu" ng-repeat="(key , value) in chats">

1 个答案:

答案 0 :(得分:0)

假设你有图表json:

$scope.chats = [
        {item: 'a',  created : '2016-12-01', num :1},
        {item: 'b',  created : '2015-12-01' , num :4},
        {item: 'c',  created : '2018-12-01', num :5},
    ];

要对项目进行排序,您需要提供过滤器orderBy : sortItem : true,如

<ul ng-repeat="(key, value) in chats | orderBy : sortItem : true">
            <li>{{value}} :: {{value.created}}</li>
        </ul>

您的控制器将具有 sortitem 功能,它将告诉分拣项目功能

<强> Conrtoller

 $scope.sortItem = function(d) {
      var dateing = new Date(d.created); 
      return dateing;  
  };

围绕jsfiddle:http://jsfiddle.net/agjqN/688/