【问题标题】:Jade not rendering variable to viewJade 不渲染变量以查看
【发布时间】:2016-04-02 00:00:43
【问题描述】:

我正在复习“使用 MEAN 堆栈构建 Angular 和 Node.js 应用程序”课程。我对 MEAN 堆栈相当陌生,特别是后端,所以如果我含糊其辞,请原谅我。所以这就是我正在做的事情......我正在尝试从 Mongodb 获取我的消息对象以使用玉显示。我没有收到任何错误,实际上我已经从视频的开头重新开始,只是为了确保我第一次没有错过任何东西。如果你愿意,我可以提供具体的细节。任何关于为什么这不起作用的想法将不胜感激。

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"
  }

【问题讨论】:

    标签: angularjs express pug mean


    【解决方案1】:

    没有任何显示,因为翡翠是基于压痕的。您需要将标签放在 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
    

    【讨论】:

    • 成功了:) 谢谢你这么好心的陌生人!!!如果我要尝试使用 Jade,我可能应该多阅读一下它。
    • 没问题。如果它对您有帮助,我将不胜感激或接受答案。
    猜你喜欢
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-26
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多