简体   繁体   中英

Node+Express+Jade : Array/Objects Not rendering

//What I am passing in [currently] to the Jade template

exports.list = function(req, res){
    res.render('report', {title: 'Custom Reports', 
        rpts:[{uri:'/reports/allocation', title:'Allocation Report'}]});
};

//The Jade template

 extends layout 
    h1 title
    ul
        each rpt in rpts
        li= a(href=rpt.uri)= rpt.title

//I see the title written in the head, but the body is empty

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

//If I remove the template extenstion, I get an error on the page

TypeError: /views/report.jade:5 3| h1 title 4| ul > 5| each rpt in rpts 6| li= a(href=rpt.uri)= rpt.title Cannot read property 'length' of undefined

it might be your formatting here in Stack, but the li tag shoudl be indented under the each declaration. Also you don't need the second = sign after the anchor.

each rpt in rpts
  li= a(href=rpt.uri) rpt.title

UPDATED Oh, and I just noticed you're missing the block directive for your content. Whatever block you declared in your layout should be placed here for rendering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM