sails.hooks.views.render local未定义

时间:2016-11-08 11:42:45

标签: javascript sails.js

使用时

    AppointmentService.getAppointmentObject(req.params.id)
        .then((response) => {
            sails.hooks.views.render('report', { appointment: response }, (err, html) => {
                if (err) return res.send(500, err);
                return res.send(200, html);
            })
        })
        .catch(err => res.status(err.status || 500).send(err.message));

我的HTML渲染,约会未定义。

使用时

    AppointmentService.getAppointmentObject(req.params.id)
        .then((appointment) => {
            res.view('report', {
                appointment,
            });
        })
        .catch(err => res.status(err.status || 500).send(err.message));

我的HTML渲染,一切按预期工作

我已经阅读了钩子source code,它应该将我的选项(因此我的约会)暴露为本地人。

我也尝试了以下内容:

sails.hooks.views.render('report', appointment, function(err, html)) // passing my object in directly
sails.hooks.views.render('report', { appointment }, function(err, html)) // es6 shorthand property

我需要钩子工作的原因是因为我需要访问HTML才能将它保存到我的S3存储桶中。

2 个答案:

答案 0 :(得分:1)

我认为它应该是css而不是sails.hooks.http.app.render

sails.hooks.views.render

答案 1 :(得分:0)

我通过使用res.render而不是res.view解决了这个问题,这让我可以访问html。

    AppointmentService.getAppointmentObject(req.params.id)
        .then((response) => {
            res.render('report', { appointment: response }, (err, html) => {
                // I can access the html here
                res.send(200, html);
            });
        })
        .catch(err => res.status(err.status || 500).send(err.message));
相关问题