我正在努力向Loopback中的一个端点添加afterRemote方法
我有两个型号:Customer
和Bills
。
A Customer has many
账单。所以Loopback为我创建了/api/Customer/{id}/bills (Get route)
我想更改该路由的响应,但我不知道如何使用afterRemote方法访问它。
为了访问Customer Model的Get路由,我写道:
Customer.afterRemote("find", function(ctx, next){SOME METHOD});
..。它工作得很好。
我尝试写这段代码来访问Customer/{id}/bills:
Customer.afterRemote("__findById__bills", function(ctx, next){SOME METHOD});
但是,尽管有文档(https://loopback.io/doc/en/lb2/Accessing-related-models.html),但这并不起作用。
有人能在这件事上帮我吗?
谢谢!
M.
发布于 2019-03-06 18:37:27
刚刚想出了解决方案。语法为:
Customer.afterRemote("*___get__bills", function(ctx, next){SOME METHOD});
发布于 2019-03-15 07:00:55
有一种简单的方法可以获得方法的名称。打开loopback explorer,打开任意型号的路由并检查url。你可以在url的末尾看到方法名。将一条下划线替换为双下划线。在您的情况下,最好通过prototype编写,而不是使用星号。
示例:
网址: localhost:3000/explorer/#!/Accounts_prototype_get_crews
钩子的方法名称: prototype.__get__crews
https://stackoverflow.com/questions/55029535
复制相似问题