我有一个实时应用,这个应用程序向我提供来自admin-site的公告。不幸的是,我无法处理排序问题,即新信息必须位于列表顶部。我的应用程序给了我列表的底部。刷新后修复了列表,但我不想刷新所有新信息。 在刷新之前:
:
controller.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);
});
}
});
}]);
routers.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)
答案 0 :(得分:1)
在HTML中:
<h3 ng-repeat="item in announcements | orderBy: '-date'">
我设法订购了orderBy过滤器