将 'persist' 中的上下文传递给 'after save'
Pass context in 'persist' to 'after save'
我需要将上下文从操作挂钩(持久化)传递到另一个操作挂钩(保存后),我知道 ctx.hookState
的 existence 但它不起作用。
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)
中没有得到任何东西。我做错了什么?
谢谢。
你不应该覆盖 hookState
你可以这样做:
ZZ.observe('persist', (ctx, next) => {
ctx.hookState.foo = "pass this";
next();
});
ZZ.observe('after save', (ctx, next) => {
console.log(ctx.hookState.foo);
next()
});
我需要将上下文从操作挂钩(持久化)传递到另一个操作挂钩(保存后),我知道 ctx.hookState
的 existence 但它不起作用。
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)
中没有得到任何东西。我做错了什么?
谢谢。
你不应该覆盖 hookState
你可以这样做:
ZZ.observe('persist', (ctx, next) => {
ctx.hookState.foo = "pass this";
next();
});
ZZ.observe('after save', (ctx, next) => {
console.log(ctx.hookState.foo);
next()
});