我是 JavaScript 和 Node 的新手。 第一:
app.get('/', function(req, res){
articleProvider.findAll(function(error, docs){
res.render('index.jade', { locals: {
title: 'Blog',
articles:docs
}
});
});
});
第二
app.get('/', function(req, res){
articleProvider.findAll(function(error, docs){
res.render('index.jade', {
title: 'Blog',
articles:docs
}
);
});
});
第一个代码来自本教程 http://howtonode.org/express-mongodb ,但不起作用。 第二个代码确实有效,但我只是不知道为什么?其他部分完全相同。
最佳答案
在 Express 的早期版本中,您需要将想要提供给 Jade 模板的变量放入 res.render
参数的 locals
字段中。
这在 3.x 中发生了变化,以便该参数的所有字段都可作为本地变量提供给渲染模板。
关于javascript 这两段代码有什么不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15238007/