玉不渲染变量来查看
Jade not rendering variable to view
我正在学习 pluralSight 的 "Building Angular and Node.js Apps with the MEAN stack" 课程。我是 MEAN 堆栈的新手,特别是后端,所以如果我含糊不清,请原谅我。所以这就是我正在进行的事情......我正在尝试从 Mongodb 获取我的消息对象以使用 jade 显示。我没有遇到任何错误,实际上我已经从视频的开头重新开始,只是为了确保我没有错过第一次的内容。如果您愿意,我可以提供具体细节。任何关于为什么这不起作用的想法将不胜感激。
index.js
var messageSchema = mongoose.Schema({message: String});
var Message = mongoose.model('Message', messageSchema);
var mongoMessage;
Message.findOne().exec(function(err, messageDoc) {
mongoMessage = messageDoc.message; //this is where i'm grabbing the data from mongodb and assigning it to this variable, right?
});
app.get('/partials/:partialPath', function(req, res) {
res.render("partials/" + req.params.partialPath);
});
app.get('*', function(req, res) {
res.render('index', { //
mongoMessage: mongoMessage //this is the variable that is not showing
});
});
index.jade
extends ../includes/layout
block main-content
section.content
div(ng-view)
h2= mongoMessage //this variable is not showing in the browser
依赖关系
"dependencies": {
"body-parser": "^1.15.0",
"bower": "^1.7.7",
"express": "^4.13.4",
"jade": "^1.11.0",
"mongoose": "^4.4.10",
"morgan": "^1.7.0",
"stylus": "^0.54.2"
}
没有显示任何内容,因为 jade 是基于缩进的。您需要像这样将标签放在 block main-content
中:
block main-content
section.content
div(ng-view)
h2= mongoMessage //this variable is not showing in the browser
而且我不确定你的代码是如何构建的,但如果你想要你的 h2 在 div 中,你也需要缩进它:
block main-content
section.content
div(ng-view)
h2= mongoMessage //this variable is not showing in the browser
我正在学习 pluralSight 的 "Building Angular and Node.js Apps with the MEAN stack" 课程。我是 MEAN 堆栈的新手,特别是后端,所以如果我含糊不清,请原谅我。所以这就是我正在进行的事情......我正在尝试从 Mongodb 获取我的消息对象以使用 jade 显示。我没有遇到任何错误,实际上我已经从视频的开头重新开始,只是为了确保我没有错过第一次的内容。如果您愿意,我可以提供具体细节。任何关于为什么这不起作用的想法将不胜感激。
index.js
var messageSchema = mongoose.Schema({message: String});
var Message = mongoose.model('Message', messageSchema);
var mongoMessage;
Message.findOne().exec(function(err, messageDoc) {
mongoMessage = messageDoc.message; //this is where i'm grabbing the data from mongodb and assigning it to this variable, right?
});
app.get('/partials/:partialPath', function(req, res) {
res.render("partials/" + req.params.partialPath);
});
app.get('*', function(req, res) {
res.render('index', { //
mongoMessage: mongoMessage //this is the variable that is not showing
});
});
index.jade
extends ../includes/layout
block main-content
section.content
div(ng-view)
h2= mongoMessage //this variable is not showing in the browser
依赖关系
"dependencies": {
"body-parser": "^1.15.0",
"bower": "^1.7.7",
"express": "^4.13.4",
"jade": "^1.11.0",
"mongoose": "^4.4.10",
"morgan": "^1.7.0",
"stylus": "^0.54.2"
}
没有显示任何内容,因为 jade 是基于缩进的。您需要像这样将标签放在 block main-content
中:
block main-content
section.content
div(ng-view)
h2= mongoMessage //this variable is not showing in the browser
而且我不确定你的代码是如何构建的,但如果你想要你的 h2 在 div 中,你也需要缩进它:
block main-content
section.content
div(ng-view)
h2= mongoMessage //this variable is not showing in the browser