你可以像这样创建一个远程方法:
User.unblock = function(id, userId, blockId, callback) {
var result;
// TODO
callback(null, result);
};
那么,json 文件中的远程方法定义可能如下所示:
"unblock": {
"accepts": [
{
"arg": "id",
"type": "string",
"required": true,
"description": "",
"http": {
"source": "path"
}
},
{
"arg": "userId",
"type": "string",
"required": false,
"description": "",
"http": {
"source": "form"
}
},
{
"arg": "blockId",
"type": "string",
"required": false,
"description": "",
"http": {
"source": "form"
}
}
],
"returns": [
{
"arg": "result",
"type": "object",
"root": false,
"description": ""
}
],
"description": "",
"http": [
{
"path": "/:id/unblock",
"verb": "post"
}
]
}
那么您的远程方法将如下所示:
您可以使用函数参数并使用一个主体参数而不是 2 个表单参数并从那里读取数据,尽管我相信如果只有 2 个附加参数,最好将它们分开放置。但这取决于你的方法。