为什么我的玉指数页空白?

时间:2014-03-18 23:21:40

标签: node.js express pug

我在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

1 个答案:

答案 0 :(得分:0)

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

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-需要一些css 每个循环本身需要{{1}}。