質問編集履歴
1
index.jsの中略の中身を書いた。
test
CHANGED
File without changes
|
test
CHANGED
@@ -90,9 +90,101 @@
|
|
90
90
|
|
91
91
|
});
|
92
92
|
|
93
|
-
|
93
|
+
router.get('/',(req, res, next) => {
|
94
|
+
|
95
|
+
|
96
|
+
|
94
|
-
|
97
|
+
new MyData()
|
98
|
+
|
99
|
+
.fetchPage({page: 1, pageSize: 3})
|
100
|
+
|
101
|
+
.then((collection) => {
|
102
|
+
|
103
|
+
var data = {
|
104
|
+
|
105
|
+
title: 'INDEX',
|
106
|
+
|
107
|
+
content: collection.toArray(),
|
108
|
+
|
109
|
+
pagination: collection.pagination
|
110
|
+
|
111
|
+
};
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
res.render('index.ejs', data);
|
116
|
+
|
117
|
+
})
|
118
|
+
|
119
|
+
.catch((err) => {
|
120
|
+
|
121
|
+
res.status(500).json({
|
122
|
+
|
123
|
+
error: true,
|
124
|
+
|
125
|
+
data: {message: err.message}
|
126
|
+
|
95
|
-
|
127
|
+
});
|
128
|
+
|
129
|
+
});
|
130
|
+
|
131
|
+
});
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
//Bookshelfでページネーションの実装
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
router.get('/:page',(req, res, next) => {
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
var pg = req.params.page;
|
146
|
+
|
147
|
+
pg *= 1;
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
new MyData()
|
152
|
+
|
153
|
+
.fetchPage({page: pg, pageSize: 3})
|
154
|
+
|
155
|
+
.then((collection) => {
|
156
|
+
|
157
|
+
var data = {
|
158
|
+
|
159
|
+
title: 'INDEX',
|
160
|
+
|
161
|
+
content: collection.toArray(),
|
162
|
+
|
163
|
+
pagination: collection.pagination
|
164
|
+
|
165
|
+
};
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
res.render('index.ejs', data);
|
170
|
+
|
171
|
+
})
|
172
|
+
|
173
|
+
.catch((err) => {
|
174
|
+
|
175
|
+
res.status(500).json({
|
176
|
+
|
177
|
+
error: true,
|
178
|
+
|
179
|
+
data: {message: err.message}
|
180
|
+
|
181
|
+
});
|
182
|
+
|
183
|
+
});
|
184
|
+
|
185
|
+
});
|
186
|
+
|
187
|
+
|
96
188
|
|
97
189
|
// /newに遷移した際の処理
|
98
190
|
|