Loopbackjs 环回错误-已调用回调
我在环回模型上使用一个观察器来存储模型数据,然后保存事件。然而我却犯了一个错误 (节点:10760)未处理的PromisejectionWarning:未处理的承诺拒绝(拒绝id:1):错误:已调用回调 下面是回调函数的实现Loopbackjs 环回错误-已调用回调,loopbackjs,Loopbackjs,我在环回模型上使用一个观察器来存储模型数据,然后保存事件。然而我却犯了一个错误 (节点:10760)未处理的PromisejectionWarning:未处理的承诺拒绝(拒绝id:1):错误:已调用回调 下面是回调函数的实现 async function eventSelObserver(ctx, next) { console.log("eventSelObserver"); if ( ! (ctx.isNewInstance) && ctx.
async function eventSelObserver(ctx, next) {
console.log("eventSelObserver");
if ( ! (ctx.isNewInstance) && ctx.currentInstance) {
ctx.hookState.SelhistoryData = [ctx.currentInstance.toObject()];
}
console.log("before calling next");
return next();
}
下面是注册回调的方法
obsModels.observe("before save", eventSelObserver);
这里,eventSelObserver内部的回调只调用一次。
有错误的指针吗?我相信这与处理异步性的方式有关,如果要使用异步/等待语法,则无需传递
下一步
。此外,您还需要等待分配的值
异步函数eventSelObserver(ctx){
log('eventSelObserver');
如果(!ctx.isNewInstance&&ctx.currentInstance){
ctx.hookState.SelhistoryData=等待ctx.currentInstance.toObject();
}
返回;
}
obsModels.observe('保存前',等待事件selobserver);
参考: