我正在使用环回。在名为Report的模型中创建一个名为stats的新方法。我想在另一个称为Acount的模型中创建该方法,但其参数为id。
模型报告:
Report.remoteMethod("stats", {
accepts: [],
returns: { arg: "features", type: "Object" },
http: { verb: "get", path: "/stats" }
});
我该如何解决?谢谢
您可以使用“接受”来定义路径参数。并且应该相应地更改http路径,“ / stats /:id”或“ /:id / stats”
Account.stats = function(id, cb) {
cb(null, 'ID ' + id);
};
Account.remoteMethod("stats", {
accepts: [
{ arg: "id", type: "number", http: { source: "path" } }
],
returns: { arg: "features", type: "Object" },
http: { verb: "get", path: "/stats/:id" }
});