环回:自动更新值

问题描述 投票:0回答:1

我有一个属性模型:statusstatusId状态可以是:

StatusId和Status描述如下:

  1. 打开
  2. 处理
  3. 拒绝
  4. 失败

我想要的是如果我插入或更新我的模型的状态,那么statusId应该相应地自动更新。

node.js loopbackjs strongloop loopback angular-loopback
1个回答
2
投票

您可以使用两件事来实现此方案

  • 使用Observe为该模型使用Remote钩子

<model>.observe('before save', function (ctx, next) { // check the ctx and add the necessary validations }

  • 如果您希望此功能成为整个应用程序的交叉关注点,请使用中间件功能

app.remotes().before('**', (ctx, next) => { // do stuff with ctx.args.options next(); });

© www.soinside.com 2019 - 2024. All rights reserved.