【问题标题】:Pass context in 'persist' to 'after save'将“持久”中的上下文传递给“保存后”
【发布时间】:2016-07-29 21:22:25
【问题描述】:

我需要将上下文从操作挂钩(持久)传递到另一个(保存后),我知道 ctx.hookStateexistence 但它不起作用。

ZZ.observe('persist', (ctx, next) => {
      ctx.hookState = "pass this";
      next();
    }).catch(err => next(err));
  });

ZZ.observe('after save', (ctx, next) => {
  console.log(ctx.hookState);
  next()
});

我在console.log(ctx.hookState) 中没有得到任何信息。我做错了什么?

谢谢。

【问题讨论】:

    标签: loopbackjs loopback


    【解决方案1】:

    你不应该覆盖hookState

    你可以这样做:

    ZZ.observe('persist', (ctx, next) => {
          ctx.hookState.foo = "pass this";
          next();    
      });
    
    ZZ.observe('after save', (ctx, next) => {
      console.log(ctx.hookState.foo);
      next()
    });
    

    【讨论】:

    • 是的,有道理!谢谢。
    猜你喜欢
    • 2015-06-02
    • 1970-01-01
    • 2019-09-19
    • 2018-10-28
    • 2020-06-25
    • 1970-01-01
    • 2021-11-14
    • 2013-04-08
    • 1970-01-01
    相关资源
    最近更新 更多