1

In my .js file I have the following data structure

var menu = { "Sport":"Racing",
    "Region":{
        "AUS":{ "name":"APrk", "key":"1234" },
        "GB":{ "name":"Cran", "key":"5678" }
    }
};
res.render('layout.jade', {locals: {menu: menu}});

In my layout.jade I have the following

for item in menu
  p= item

This produces the following output

Racing

[object Object]

Which is on the right track. What I would like to know is how can I access the nested structures?

Hoa
  • 19,858
  • 28
  • 78
  • 107

1 Answers1

9

I believe you're looking for this

// layout.jade
each value, key in locals.menu
  // may nest more iteration
  each v, k in value

Iteration of object key/value does not grantee order. You may want to use array.

Details: https://github.com/visionmedia/jade#a9

James Moore
  • 2,501
  • 6
  • 26
  • 29
ming_codes
  • 2,870
  • 25
  • 24