Loopback中静态远程方法及其方法签名的定义(Definition of static remote methods and their method signatures in Loopback

编程入门 行业动态 更新时间:2024-10-23 01:35:28
Loopback中静态远程方法及其方法签名的定义(Definition of static remote methods and their method signatures in Loopback)

从loopback文档中可以看出:

beforeRemote()和afterRemote()都具有相同的签名; 下面的语法使用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有三个参数。

是否有不同的定义或静态方法列表?

From the loopback documentation it states that:

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(); });

The documentation then goes on to say ...

Static methods have URL /api/modelName/methodName, while prototype methods have URL /api/mod elName/id/methodName.

Elsewhere, an example is provided

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(); }); };

Based on the above documentation ... I would expect that create would be a static method and therefore only have two arguments (but yet in this example above, and in practice, beforeRemote for create has three arguments.

Is there a different definition or a list of a static methods available?

最满意答案

我认为这是文档中的错误,因为PersistedModel.create是一个静态方法。

静态和实例方法的列表在参考文档中:

https://apidocs.strongloop.com/loopback/v/2.27.0/#persistedmodel

I think this is an error in the documentation, since PersistedModel.create is a static method.

A list of static and instance methods is in the reference docs:

https://apidocs.strongloop.com/loopback/v/2.27.0/#persistedmodel

更多推荐

本文发布于:2023-07-07 21:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1068529.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   静态   定义   Definition   Loopback

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!