Loopback 中静态远程方法的定义及其方法签名
Definition of static remote methods and their method signatures in Loopback
环回文档指出:
Both beforeRemote() and afterRemote() have the same signature; below
syntax uses beforeRemote but afterRemote is the same. For static
remote methods, including custom remote methods:
modelName.beforeRemote( methodName, function(ctx, next) { ...
next();
});
文档接着说...
Static methods have URL /api/modelName/methodName, while prototype
methods have URL /api/mod elName/id/methodName.
别处提供了一个例子
module.exports = function(Review) {
Review.beforeRemote('create', function(context, user, next) {
var req = context.req;
req.body.date = Date.now();
req.body.publisherId = req.accessToken.userId;
next();
}); };
根据上述文档...我希望 create
是一个静态方法,因此只有两个参数(但在上面的这个例子中,在实践中,beforeRemote
for create
有三个参数。
是否有不同的定义或可用的静态方法列表?
我认为这是文档中的一个错误,因为 PersistedModel.create 是一个静态方法。
静态和实例方法列表在参考文档中:
https://apidocs.strongloop.com/loopback/v/2.27.0/#persistedmodel
环回文档指出:
Both beforeRemote() and afterRemote() have the same signature; below syntax uses beforeRemote but afterRemote is the same. For static remote methods, including custom remote methods:
modelName.beforeRemote( methodName, function(ctx, next) { ... next(); });
文档接着说...
Static methods have URL /api/modelName/methodName, while prototype methods have URL /api/mod elName/id/methodName.
别处提供了一个例子
module.exports = function(Review) {
Review.beforeRemote('create', function(context, user, next) {
var req = context.req;
req.body.date = Date.now();
req.body.publisherId = req.accessToken.userId;
next();
}); };
根据上述文档...我希望 create
是一个静态方法,因此只有两个参数(但在上面的这个例子中,在实践中,beforeRemote
for create
有三个参数。
是否有不同的定义或可用的静态方法列表?
我认为这是文档中的一个错误,因为 PersistedModel.create 是一个静态方法。
静态和实例方法列表在参考文档中:
https://apidocs.strongloop.com/loopback/v/2.27.0/#persistedmodel