【发布时间】:2016-09-22 15:49:01
【问题描述】:
我正在探索 PUG 模板并拥有 exporess/mongodb/mongoose 后端。
索引页面的路由器用于显示“推荐”,我有以下“路线”:
const Testimonial = require('../models/Testimonial');
exports.index = (req, res) => {
Testimonial.find((err, testimonials) => {
if (err) {
console.log("Error: " + err);
} else {
res.render('home2', {
title: 'website',
testimonials: testimonials,
});
}
});
};
如果我在渲染之前添加一个“console.log”语句,它将返回集合中的所有推荐,因此数据端可以工作。
索引页面包含一个用于推荐的“部分”哈巴狗模板,其中包含以下内容:
.nk-box.bg-gray-4
.nk-gap-4
.row
.nk-carousel-2(data-autoplay='12000', data-dots='true')
.nk-carousel-inner
each testimonial in testimonials
div
div
blockquote.nk-testimonial-3
.nk-testimonial-photo(style="background-image: url('/images/avatar-man-2.jpg');")
.nk-testimonial-body
em
| " testimonial.Description "
.nk-testimonial-name.h4 testimonial.CreatedBy
.nk-testimonial-source testimonial.ModifiedDate
.nk-gap-4
模板创建了正确数量的推荐信,但没有显示每个推荐信中的数据。相反,我得到了一个用“testimonial.Description”而不是实际单词和“testimonial.CreatedBy”而不是人名的推荐。
模板正在循环查看它返回的内容,我只是无法显示数据。
如果你们能提供任何帮助,我将不胜感激。
再次感谢。
【问题讨论】: