【发布时间】:2019-02-03 14:27:14
【问题描述】:
我正在尝试使用 Pug 进行模板创建一个快速应用程序。我无法弄清楚为什么当我使用无缓冲变量插值时,对象是未定义的,但是当我删除破折号时它似乎工作得很好(减去它实际上显示的对象)
//index.pug
extends layout
block campground
- var campgrounds = '#{camps}'
.row
each campground in campgrounds
div.col-md-3.col-sm-6
div
img(src=`${campground.image}` class='img-thumbnail')
a(href=`/campgrounds/${campground._id}`)
h4.caption.text-center #{campground.name}
//app.js
app.get('/campgrounds', async (req, res) => {
try {
const camps = await Camp.find();
res.render('index', { camps: camps });
} catch (ex) {
res.status(500).send('internal error');
}
});
语法 1:
- var campgrounds = '#{camps}'
生产:
语法 2:
var campgrounds = '#{camps}'
生产:
【问题讨论】: