【问题标题】:Why is my jade index page blank?为什么我的翡翠索引页是空白的?
【发布时间】:2014-04-24 22:45:24
【问题描述】:

我在 Express、Mongo 和 Jade 上广泛关注本教程,虽然我已经成功地从 mongo 取回了一些数据,但 Jade 并没有呈现我的页面。 http://blog.ijasoneverett.com/2013/03/a-sample-app-with-node-js-express-and-mongodb-part-1/

片段是:

app.js:

app.get('/', function(req, res) {
    employeeProvider.findAll(function(error, emps) {
        // adding logging here shows that 'title' and 'emps' are correctly populated 
        res.render('index', { title:'Employees', employees:emps });
    });
});

layout.jade:

doctype html
html
    head
        title= title
        link(rel='stylesheet', href='/stylesheets/style.css')
    body
        block content

index.jade:

extends layout

block content    
    h1= title
    div
        each employee in employees
            div.employee
                div.created_at= employee.created_at
                div.title= employee.title
                div.name= employee.name

当我从浏览器中显示的页面中提取源代码时,它只是显示如下:

<!DOCTYPE html><html><head><title>Employees</title><link rel="stylesheet" href="/stylesheets/style.css"></head><body></body></html>

事实上,我在jade.index 中添加的任何内容似乎都没有被渲染。例如,这也会呈现一个空白页面:

index.jade:

extends layout

block content    
    h1= title

【问题讨论】:

  • 我认为文件应该被称为index.jadelayout.jade,而不是jade.index等。
  • 确实你是对的,它们被称为 index.jade 等。我在输入我的问题时转调了。我会编辑这个问题。谢谢

标签: node.js express pug


【解决方案1】:

再次检查教程并按照它(真的),因为你的代码是不同的......

http://blog.ijasoneverett.com/2013/03/a-sample-app-with-node-js-express-and-mongodb-part-1/

index.jade 应该是:

extends layout

block content
    h1= title
    #employees
        - each employee in employees
          div.employee
            div.created_at= employee.created_at
            div.title= employee.title 
            div.name= employee.name
        a(href="/employee/new")!= "Add New Employee"

#employees 和 每个循环都需要一个 - 在它之前。

【讨论】:

  • 我从该代码开始,但它没有工作。我在其他地方看到了不使用 - 的例子。无论如何,我的第二个示例(代码基本上只是'h1 = title')应该在屏幕上打印一些东西,但不会。
猜你喜欢
  • 2022-10-15
  • 1970-01-01
  • 2020-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多