我是 Strongloop 的新手,查看文档和示例,但从未看到我想要的问题。 例如,我有两个模型,sentence.js 和 log.js,并将 post 请求从移动应用程序发送到rest-api
Model sentence.js (dont want save to db this model, only for parsing and creating log model)
{
name: 'sentence',
type: 'string'
}
Model log.js
{ name: 'lat', type: 'string' },
{ name: 'lng', type: 'string' }
[HTTP POST] myserver/api/sentence?d=$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
模型具有触发方法,例如 afterInitialize、beforeValidate、beforeSave。现在,哪个触发方法或任何其他范围正确且最适合解析句子模型和创建日志模型?
谢谢!
最佳答案
就你而言,最好的地方是
Sentence.beforeRemote('create', function(ctx, sentence, next){
console.log(ctx.req.body);
next()
})
还有Model hook Sentence.afterInitialize
和 Model Event Sentence.on('set')
可用,但在某些额外情况下会被调用。
(请注意,在我的例子中,我将使用远程 Hook 并且仅使用一个日志模型。)
关于node.js - 在模型中创建模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27599031/