在Loopback中使用node.js在模型上引用属性

试图非常参考一个属性与回环,并考虑了多less时间,我试图做到这一点,我显然想念一些基本的概念。

很简单,我有一个问题模型有点作为一个整数属性,我想要做的只是打印出点属性到控制台。

module.exports = function(Question) { Question.observe('after save', function(ctx, next) { console.log(Question.prototype.points) next(); }); }; 

当我这样做,它打印出undefined

考虑到这是一个简单的操作,我错过了什么?

json文件:

 { "name": "Question", "plural": "Questions", "base": "PersistedModel", "idInjection": true, "options": { "validateUpsert": true }, "properties": { "text": { "type": "string", "required": true }, "points": { "type": "number", "required": true } }, } 

你几乎在那里。 保存后使用上下文对象。

 module.exports = function(Question) { Question.observe('after save', function(ctx, next) { console.log(ctx.instance.points); next(); }); }; 

操作钩子文档。