【问题标题】:Is it possible to get model definition in callback override in sails.js?是否可以在sails.js 的回调覆盖中获取模型定义?
【发布时间】:2016-01-14 22:17:16
【问题描述】:

我正在研究类似于Can I specify a lifecycle callback that fires for all waterline models in sails? 的东西。

我希望能够在回调中引用模型定义,但当前只有属性和 id 被发送到 afterUpdate。除了添加“类型”作为属性之外,有没有办法确定我正在使用的模型?

【问题讨论】:

    标签: sails.js waterline


    【解决方案1】:

    正确的范围加上 this 将在 config/models.js 中工作。

    module.exports.models = {
    
        attributes: { . . .},
    
        afterUpdate: function (model) {
            console.log(this.identity);  //model name that triggered callback
            console.log(this.definition); //model definition
    
            //logic . . .
        }
    };
    

    【讨论】:

      猜你喜欢
      • 2014-01-07
      • 2011-06-13
      • 2017-01-18
      • 2019-01-26
      • 2018-09-10
      • 2012-07-01
      • 1970-01-01
      • 2012-02-12
      • 2019-08-21
      相关资源
      最近更新 更多