这些天我正在学习 MEAN stack,所以我按照指导制作了一些示例应用程序。几个小时前我制作了“书架”应用程序,这是由谷歌云服务提供的,所以我应该深入研究示例代码以了解它是如何工作的。
完整源代码:https ://github.com/GoogleCloudPlatform/nodejs-getting-started/tree/master/2-structured-data
示例应用程序:http: //mymongo-1165.appspot.com/books
书籍/api.js
router.get('/', function list(req, res) {
model.list(10, req.query.pageToken,
function(err, entities, cursor) {
if (err) { return handleRpcError(err, res); }
res.json({
items: entities,
nextPageToken: cursor
});
});
});
书籍/curd.js
router.get('/', function list(req, res) {
model.list(10, req.query.pageToken,
function(err, entities, cursor) {
if (err) { return handleRpcError(err, res); }
res.render('books/list.jade', {
books: entities,
nextPageToken: cursor
});
}
);
});
这两个代码是相似的,但我不知道为什么会出现这些相似的代码。我认为 crud.js 就够了,但是为什么 api.js 会出现。你能解释一下这两个代码是如何工作的吗?