Skip to content

Commit 4d53597

Browse files
committed
pagination jprichardson#2
1 parent f05997f commit 4d53597

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

client/js/app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ function ListCtrl ($scope, $http, CarsService) {
8888
}
8989

9090
$scope.loadPage = function (pg) {
91-
91+
$scope.offset = pg - 1
92+
$scope.cars = CarsService.query({offset: $scope.offset, limit: $scope.limit})
9293
}
9394

9495
}

server/api/cars.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ var DATA = fs.readJsonSync(DATA_FILE) //happens at server startup
2020
**********************/
2121

2222
function list (req, res) {
23-
res.json(_(DATA).take(25))
23+
var offset = ~~req.query.offset || 0
24+
, limit = ~~req.query.limit || 25
25+
26+
res.json(DATA.slice(offset*limit, offset*limit + limit))
2427
}
2528

2629
function create (req, res) {

0 commit comments

Comments
 (0)