Jade Template Trouble accessing Values from view data

82 views Asked by At

I've passed an object to my jade template from express:

connection.invokeQuery(sqlStatement, function(rows){
    res.render('index', { title: 'App', companies: rows});
});

here's my template

extends layout
block content
    h1= title
    div
        each company in companies
           p #{company.City}

that works, I can render a city list. But I'm not sure how to get at the root property or sub properties and objects within an object with jade.

For example lets say the json for company was this:

   [{
        companyName: 'Apple',
            City: 'Milwaukee',
            State: 'WI ',
            StateName: 'Wisconsin',
            Country: 'United States',
            Region: 'North America',
            PostalCode: '53201-0371'},
            {
               Website: 'www.apple.com',
               ....
            },
        ... and so on

    }]

I tried company.companyName and it doesn't work.

Also how would I reference the property "Website"? It's in another object below in this array.

1

There are 1 answers

3
Kris Molinari On

From what I'm seeing here, you have multiple objects inside an array. You wouldn't be able to access "Website" as it is in another object. The each statement is iterating over the array containing your objects. You could access it in the second iteration of your each statement, but no other properties of the first object. If you wanted access to that value, it must be a part of the same object.