0
我有一個實時應用程序,這個應用程序提供了從管理網站公告。不幸的是,我無法處理新信息必須位於列表頂部的訂購問題。我的應用程序給了我列表的底部。刷新後修復了列表,但我不想刷新所有新的信息。 刷新之前:swampdragon對象沒有正確訂購
- AFAS 2015年7月21日12時07分10秒
- 5分鐘2015年7月21日12時07分03秒
- 5分鐘2015年7月21日12時27分: 16
刷新後:
- 5分鐘2015年7月21日12點27分16秒
- AFAS 2015年7月21日12時07分10秒 個
- 5分鐘2015年7月21日12時07分03秒
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)