在LoopBack中扩展CRUD方法 [英] extend the CRUD method in LoopBack
本文介绍了在LoopBack中扩展CRUD方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何扩展LoopBack创建的CRUD方法.
I would like to know how to extend CRUD methods created by LoopBack.
我有一个属性为public_key
的模型.我想为此模型的POST
api端点构建两个自定义行为.
I have a model with an attribute public_key
. I would like to build two custom behaviors for the POST
api endpoint for this model.
- 生成公共密钥并设置值
- 生成私钥并将其作为结果发送回(使用SSL)
如何扩展默认方法来实现这些行为?
How can I extend the default method to implement these behaviors?
推荐答案
我能够通过在server/boot
下创建一个javascript文件来覆盖默认方法.
I was able to override the default method by creating a javascript file under server/boot
.
module.exports = function(app) {
var MyModel = app.models.MyModel;
var create = MyModel.create;
// Overrides POST '/api/MyModel' endpoint
MyModel.create = function(data, done) {
// Do custom things
create.call(MyModel, data, done);
};
};
但是我无法修改返回值.
However I was not able to modify the return value.
这篇关于在LoopBack中扩展CRUD方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文