SailsJS:beforeUpdate(生命周期回调),访问当前值 [英] SailsJS: beforeUpdate (Lifecycle callback), access current values

查看:54
本文介绍了SailsJS:beforeUpdate(生命周期回调),访问当前值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很清楚如何访问新值,第一个参数包含它们

It's clear how to access the new values, the first argument contains them

beforeUpdate: function (values, cb) {....}

但是我如何访问要替换的当前值?

But how can I access the current values, that are to be replaced?

推荐答案

为了访问当前值,您必须进行调用并获取当前记录.

In order do access current values you will have to make the call and get the current record.

models/user.js
beforeCreate: function (values, cb) {
    User.findOne(this.update.arguments[0].id || this.update.arguments[0]).exec(err, function(originalUser){/*...*/})
}

另请查看https://github.com/balderdashy/waterline/issues/1004#issuecomment-102432862 ,这里正在讨论这个问题.应提供有关获取 ID 和当前解决方案的见解.

Also check out https://github.com/balderdashy/waterline/issues/1004#issuecomment-102432862 , where this issue is being discussed. Should provide insight into getting the ID and a current solution.

以上解决方案已更新以反映评论.

The solution above was updated to reflect the comments.

这篇关于SailsJS:beforeUpdate(生命周期回调),访问当前值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆