环回中静态远程方法及其方法签名的定义

Definition of static remote methods and their method signatures in Loopback

本文关键字:方法 定义 静态 程方法      更新时间:2023-09-26

从环回文档中,它指出:

beforeRemote() 和 afterRemote() 都有相同的签名;下面 语法在远程之前和之后使用远程是相同的。对于静态 远程方法,包括自定义远程方法:

modelName.beforeRemote( methodName, function(ctx, next) { ...
   next(); 
});

然后文档继续说...

静态方法有 URL/api/modelName/methodName,而原型 方法有 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