现在,我想触发默认蓝图 触发后的操作。例如,如果我请求example.com/user并用POST发送 ,我希望蓝图路由将信息插入到数据库 中,然后执行其他操作,我该怎么做?
Lifecycle callbacks旨在解决这类问题。它们是在某些模型操作之前或之后自动调用的函数。例如。 using afterUpdate
module.exports = {
attributes: {
username: {
type: 'string',
required: true
},
password: {
type: 'string',
minLength: 6,
required: true,
columnName: 'hashed_password'
}
},
// Lifecycle Callbacks
afterUpdate: function (values, cb) {
// notify user about updated profile
}
};
当您需要更大的灵活性,你必须创建像这样
update: function(req, res) {
User.update(req.body).exec(function(err, result){
if (err) {
// ups
}
return res.redirect('/something-after')
});
}
模型的动作而你可以通过简单地重定向到它调用另一个动作。
你能分享一些代码来阐述你打算做什么吗? – gnerkus