这是另一个后续到之前的question。只涉及两种模式:category
和game
,它们共享hasMany
关系。示例:端点/Categories/1001/games/mature
列出所有fighting
类别的游戏,其中mature
标志设置为true
。但是,我无法对paginate
作出回应。基于下面显示的代码分页的正确方法是什么?我想一次只显示10个结果。分页相关型号的结果
通用/模型/ category.js
Category.mature = function(id, callback) {
var app = this.app;
var Game = app.models.game;
Category.findById(id, {}, function(err, category) {
if (err) return callback(err);
//Now call the Game find method
Game.find({
"where": {
categoryId: id,
mature: true
}
}, function(err, gameArr) {
if (err) return callback(err);
callback(null, gameArr);
});
});
}
Category.remoteMethod(
'mature', {
accepts: [{
arg: 'id',
type: 'number',
required: true
}],
// mixing ':id' into the rest url allows $owner to be determined and used for access control
http: {
path: '/:id/games/mature',
verb: 'get'
},
returns: {
arg: 'games',
type: 'array'
}
}
);
表/型号
catgories
category_name category_id
------------- -----------
fighting 1001
racing 1002
sports 1003
games
game_id game_name category_id mature description published_date
----------- ------------ ----------- ------- ----------- --------------
13KXZ74XL8M Tekken 10001 true Published by Namco. 1994
138XZ5LPJgM Forza 10002 false Published by Microsoft 2005
API结果:
games [
{
gameName: 'Tekken',
gameInfo :
[
{
description : 'Published by Namco.',
published_date : '1994'
}
],
categorName: 'fighting',
categoryId: 1001,
mature: true
}
.....
]
有没有办法通过url将'skip'的值传递给远程方法? –
是的,看我的更新。 – Brian
是否可以使用'gameId'作为偏移来显示下一个'x'项目,而不是使用'skip'。有些人喜欢'/ 1/games/mature?nextid = 13KXZ74XL8M' –