javascript – 如何将视图呈现给字符串?
作者:互联网
我想在sailsjs控制器/动作中呈现特定视图,该视图应作为电子邮件发送.
我有以下示例操作:
function registerAction(req, res) {
// handle user registration
// email user
sendEmail({
to: newUser.email,
subject: "Welcome",
text: /* VIEW RENDER HERE */
});
// render view to the user
return res.view({
user: newUser
});
}
如何使用sailsjs提供的工具呈现视图模板,以便我不需要对电子邮件文本进行硬编码或使用其他库?
提前致谢!
解决方法:
Express’res.render()
在您的res对象中仍然是accessible.
function registerAction(req, res) {
// handle user registration
res.render('/path/to/view', function (err, html) {
// email user
sendEmail({
to: newUser.email,
subject: "Welcome",
text: html
});
}
// render view to the user
return res.view({
user: newUser
});
}
标签:javascript,sails-js,rendering,views 来源: https://codeday.me/bug/20191003/1845858.html