2016-07-28 58 views
0

我需要將操作鉤(持續)傳遞到另一個(保存後),我知道的existence,但它不起作用。將'persist'中的上下文傳遞給''保存後'

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)沒有得到任何東西。我做錯了什麼?

謝謝。

回答

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() 
}); 
+0

呀,讓一切的感覺!謝謝。 –

相關問題