回送之前为PUT请求的远程
使用Loopback框架,我想在编辑Item
之前执行一些操作,因此我正在尝试这个,但无法将其绑定到更新挂钩。
Item.beforeRemote("update", function(ctx,myitem,next) { console.log("inside update"); });
而不是更新我已经尝试updateAttributes , updateById , 创build但没有任何作品。 这种beforeRemote钩子在POST上创build的效果很好,但是在编辑过程中无法使用PUT来获得它。 我最后的解决scheme是再次检查methodString与通配符钩,但我想知道是否有什么logging,我找不到。
Item.beforeRemote("**",function(ctx,instance,next){ console.log("inside update"); });
与注释相反, save
是一个远程钩子,而不是一个操作钩子,但是你想用它作为: prototype.save
。 相关的操作钩子将before save
。 您可以在LoopBack文档页面上看到这些表格。 我可能会实现这个作为一个可操作的钩子,并在上下文使用isNewInstance
属性只执行更新的行动:
Item.observe('before save', function(ctx, next) { if (ctx.isNewInstance) { // do something with ctx.currentInstance } next(); });
对不起,碰到老问题,但对于那些仍在寻找。
可以将“prototype.updateAttributes”用作更新请求的远程挂钩。 和@jakerella,没有远程钩叫'保存',我自己试了一下,但没有工作。