您好stackoverflow社区
首先,我想说我仍然是一个有角度的绝对初学者。 我有一个小问题,为观察名单加分。
数据来自Typo3作为json文件。
<div class="watchlist" ng-app="watchlist" ng-init="watchlists = {json}">
观看名单是手风琴:
<div ng-repeat="watchlist in watchlists | orderBy:sortType:sortReverse" ng-controller="watchlistController" class="watchlistpanel-top">
每支手风琴都有产品:
<div ng-repeat="product in products | orderBy:sortType:sortReverseproducts" ng-controller="productController">
寻呼机:
<uib-pagination ng-if="watchlistcount > paginationWatch.pagesizeWatch " boundary-links="true" total-items="12" ng-model="paginationWatch.pageWatch" items-per-page="paginationWatch.pagesizeWatch" ng-change="changeOffsetLink(paginationWatch.pageOffset)" class="pagination-sm" previous-text="‹" next-text="›" first-text="«" last-text="»"></uib-pagination>
应用文件:
app.controller('watchlistController', ['$scope', '$http', '$attrs', '$uibModal', function($scope, $http, $attrs, $uibModal) {
$scope.products = [];
$scope.watchlistsList = [];
$scope.status = {
open: false
};
$scope.pagination = {
page: 1,
pagesize: 100
};
$scope.editDescription = null;
$scope.$watchGroup([
'status.open',
'pagination.page'
], function() {
if($scope.status.open) {
loadItems();
}
});
var loadItems = function() {
$scope.loading = true;
$scope.products = [];
$http({
method: 'GET',
url: location.href.replace(location.hash,""),
params: {
'type': 2046,
'tx_foshopproducts_watchlist[controller]': 'WatchlistProduct',
'tx_foshopproducts_watchlist[action]': 'get',
'tx_foshopproducts_watchlist[watchlist]': $scope.watchlist.WatchListTree_ID,
'tx_foshopproducts_watchlist[offset]': ($scope.pagination.page - 1) * $scope.pagination.pagesize,
'tx_foshopproducts_watchlist[limit]': $scope.pagination.pagesize,
}
}).then(function (response) {
$scope.products = response.data;
$scope.loading = false;
});
};
$scope.paginationWatch={
pageWatch:1,
pagesizeWatch:10,
pageOffset:0
};
var loadwatchItems = function() {
$scope.loadingwatchlists = true;
$scope.watchlistsList = [];
$http({
method: 'GET',
url: location.href.replace(location.hash,""),
params: {
'type': 2046,
'tx_foshopproducts_watchlist[controller]': 'Watchlist',
'tx_foshopproducts_watchlist[action]': 'get',
'tx_foshopproducts_watchlist[offset]': $scope.paginationWatch.pageOffset,
'tx_foshopproducts_watchlist[limit]': $scope.paginationWatch.pagesizeWatch,
}
}).then(function (response) {
$scope.watchlistsList = response.data;
$scope.loadingwatchlists = false;
$scope.watchlistcount = $scope.watchlistsList[$scope.watchlistsList.length-1];
});
};
loadwatchItems();
$scope.changeOffsetLink = function() {
$scope.paginationWatch.pageOffset = ($scope.paginationWatch.pageWatch - 1) * $scope.paginationWatch.pagesizeWatch;
loadwatchItems();
}
$scope.create = function() {
var modalInstance = $uibModal.open({
templateUrl: 'watchlistCreateModal',
backdrop: 'static',
controller: 'createWatchlistController'
});
modalInstance.result.then(function(watchlist) {
if(watchlist) {
$scope.watchlists.push(watchlist);
$scope.watchlists.sort(function(a, b) {
return a.Description.toString().localeCompare(b.Description);
});
}
});
};
$scope.edit = function($event) {
$event.stopPropagation();
$event.preventDefault();
var modalInstance = $uibModal.open({
templateUrl: 'watchlistEditModal',
backdrop: 'static',
controller: 'editWatchlistController',
resolve: {
watchlist: function () {
return $scope.watchlist
}
}
});
modalInstance.result.then(function(watchlist) {
if(watchlist) {
$scope.watchlist = watchlist;
}
else {
$scope.watchlists = $scope.watchlists.splice($scope.$index, 1);
}
});
};
}]);
现在我遇到的问题是它产生了很多GET请求而且Pager不起作用。 有人可以帮我解决这些问题吗?