0

我有一个实时应用程序,这个应用程序为我提供来自管理站点的公告。不幸的是,我无法处理新信息必须在列表顶部的订购问题。我的应用程序给了我列表的底部。刷新后它修复了列表,但我不想刷新所有新信息。刷新前:

  • 阿法斯 2015-07-21 12:07:10
  • 5 分钟 2015-07-21 12:07:03
  • 5 分钟 2015-07-21 12:27:16

刷新后:

  • 5 分钟 2015-07-21 12:27:16
  • 阿法斯 2015-07-21 12:07:10
  • 5 分钟 2015-07-21 12:07:03

控制器.js:

var AnnounceControllers = angular.module('AnnounceControllers', []);

AnnounceControllers.controller('AnnounceListCtrl', ['$scope', '$dragon', function ($scope, $dragon) {
$scope.announceList = {};
$scope.announcements = [];
$scope.channel = 'announce';

$dragon.onReady(function() {
    $dragon.subscribe('announcements', $scope.channel, {announce_list__id: 1}).then(function(response) {
        $scope.dataMapper = new DataMapper(response.data);
    });

    $dragon.getSingle('announce-list', {id:1}).then(function(response) {
        $scope.announceList = response.data;
    });

    $dragon.getList('announcements', {list_id:1}).then(function(response) {
        $scope.announcements = response.data;
    });
});

$dragon.onChannelMessage(function(channels, message) {
    if (indexOf.call(channels, $scope.channel) > -1) {
        $scope.$apply(function() {
            $scope.dataMapper.mapData($scope.announcements, message);
        });
    }
});
}]);

路由器.py:

from swampdragon import route_handler
from swampdragon.route_handler import ModelRouter
from post.models import AnnounceList, Announce
from post.serializers import AnnounceListSerializer, AnnounceSerializer


class AnnounceListRouter(ModelRouter):
    route_name = 'announce-list'
    serializer_class = AnnounceListSerializer
    model = AnnounceList

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['id'])

    def get_query_set(self, **kwargs):
        return self.model.objects.all()


class AnnounceRouter(ModelRouter):
    route_name = 'announcements'
    serializer_class = AnnounceSerializer
    model = Announce

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['id'])

    def get_query_set(self, **kwargs):
        return  self.model.objects.filter(announce_list__id=kwargs['list_id']).order_by("-pub_date")


route_handler.register(AnnounceListRouter)
route_handler.register(AnnounceRouter)
4

1 回答 1

1

在 HTML 中:

<h3 ng-repeat="item in announcements | orderBy: '-date'">

我设法用 orderBy 过滤器订购

于 2015-07-21T09:43:40.897 回答