gpt4 book ai didi

javascript - SailsJS : accessing res. 在 beforeCreate 或 afterCreate 中呈现

转载 作者:行者123 更新时间:2023-11-30 12:49:44 25 4
gpt4 key购买 nike

我需要访问 beforeCreate 中的 res.render 函数以呈现 html 模板,但似乎 res object 没有传递给那个函数。我该怎么做?

据我所知,这是 afterCreate 得到的:

afterCreate: function(attrs, next) {
// attrs is basically just the model
next();
}

最佳答案

您可以使用位于 sails.express.app.render 中的全局 Express 渲染器,因此在您的模型中它可以是这样的:

module.exports = {
beforeCreate: function(values, next) {
sails.express.app.render('home', {locals: {}}, function(err, html) {
console.log(html);
next();
});
}
};

关于javascript - SailsJS : accessing res. 在 beforeCreate 或 afterCreate 中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21353594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com