http://howtonode.org/express-mongodb 我尝试运行此示例,当我尝试运行节点app.js时,我收到了一个ReferenceError。
这是错误: 500 ReferenceError:/home/action/blog/views/index.jade:4 2 | h1 =标题3 | #articles> 4 | - 第5条中的每篇文章div.article 6 | div.created_at = article.created_at 7 | div.title title未定义
2| h1= title
3| #articles
4| - each article in articles
5| div.article
6| div.created_at= article.created_at
7| div.title
title is not defined
at eval (eval at (/home/action/blog/node_modules/jade/lib/jade.js:176:8), :19:15)
at /home/action/blog/node_modules/jade/lib/jade.js:181:12
at Object.exports.render (/home/action/blog/node_modules/jade/lib/jade.js:216:14)
at View.exports.renderFile [as engine] (/home/action/blog/node_modules/jade/lib/jade.js:243:13)
at View.render (/home/action/blog/node_modules/express/lib/view.js:75:8)
at Function.app.render (/home/action/blog/node_modules/express/lib/application.js:504:10)
at ServerResponse.res.render (/home/action/blog/node_modules/express/lib/response.js:753:7)
at /home/action/blog/app.js:38:13
at /home/action/blog/articleprovider-mongodb.js:43:16
at /home/action/blog/node_modules/mongodb/lib/mongodb/cursor.js:159:16
它是index.jade文件中的内容,但我似乎无法弄清楚它出错的地方。
编辑添加: 这是index.jade文件:
block content
h1= title
#articles
- each article in articles
div.article
div.created_at= article.created_at
div.title
a(href="/blog/"+article._id.toHexString())!= article.title
div.body= article.body
extends layout
这里是索引页面的app.get:
app.get('/', function(req, res){
articleProvider.findAll( function(error,docs){
res.render('index.jade', { locals: {
title: 'Blog',
articles:docs
}
});
})
});
它在功能中传递了标题,所以我真的不确定问题是什么。
答案 0 :(得分:0)
好的,所以我认为快递render
API已经发生了变化。尝试删除“locals”属性并直接传递数据:
app.get('/', function(req, res){
articleProvider.findAll( function(error,docs){
res.render('index.jade', {
title: 'Blog',
articles:docs
});
});
});