質問編集履歴
1
index.jsの中略の中身を書いた。
title
CHANGED
File without changes
|
body
CHANGED
@@ -44,8 +44,54 @@
|
|
44
44
|
var MyData = Bookshelf.Model.extend({
|
45
45
|
tableName: 'zatu'
|
46
46
|
});
|
47
|
+
router.get('/',(req, res, next) => {
|
47
48
|
|
49
|
+
new MyData()
|
50
|
+
.fetchPage({page: 1, pageSize: 3})
|
51
|
+
.then((collection) => {
|
52
|
+
var data = {
|
53
|
+
title: 'INDEX',
|
54
|
+
content: collection.toArray(),
|
55
|
+
pagination: collection.pagination
|
56
|
+
};
|
57
|
+
|
58
|
+
res.render('index.ejs', data);
|
59
|
+
})
|
60
|
+
.catch((err) => {
|
61
|
+
res.status(500).json({
|
62
|
+
error: true,
|
63
|
+
data: {message: err.message}
|
48
|
-
|
64
|
+
});
|
65
|
+
});
|
66
|
+
});
|
67
|
+
|
68
|
+
|
69
|
+
//Bookshelfでページネーションの実装
|
70
|
+
|
71
|
+
router.get('/:page',(req, res, next) => {
|
72
|
+
|
73
|
+
var pg = req.params.page;
|
74
|
+
pg *= 1;
|
75
|
+
|
76
|
+
new MyData()
|
77
|
+
.fetchPage({page: pg, pageSize: 3})
|
78
|
+
.then((collection) => {
|
79
|
+
var data = {
|
80
|
+
title: 'INDEX',
|
81
|
+
content: collection.toArray(),
|
82
|
+
pagination: collection.pagination
|
83
|
+
};
|
84
|
+
|
85
|
+
res.render('index.ejs', data);
|
86
|
+
})
|
87
|
+
.catch((err) => {
|
88
|
+
res.status(500).json({
|
89
|
+
error: true,
|
90
|
+
data: {message: err.message}
|
91
|
+
});
|
92
|
+
});
|
93
|
+
});
|
94
|
+
|
49
95
|
// /newに遷移した際の処理
|
50
96
|
router.get('/new', (req, res, next) => {
|
51
97
|
|