Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic html pages with Jade, NodeJS, Express

I have a big json object containing cell data from a sample spreadsheet that has been retrieved from redis keystore. I want to show it in a html table format in the jade template. But for now, all I can show it as is a json string.

I am also unclear about how to generate dynamic web pages using jade/express.

Sample JSON string am trying to pass:

{"1A":"Cell Data 1", "1B": "Cell Data 2",...}

It is data from an excel spreadsheet.

Please help me to clear this doubt.

like image 330
Dragunov Avatar asked Mar 05 '11 15:03

Dragunov


1 Answers

table
  thead
    tr
      th Name
      th Food
  tbody
    - var items = [{name:'Dean',food:'Chicken'}, {name:'Paul',food:'steak'}]
    - each item in items
      tr
        td= item.name
        td= item.food

outputs

<table><thead><tr><th>Name</th><th>Food</th></tr></thead><tbody><tr><td>Dean</td><td>Chicken</td></tr><tr><td>Paul</td><td>steak</td></tr></tbody></table>

or more practically than defining the items array of objects in jade

var items = dynamicallyGenerateYourJson();
res.render('table', {
  items: items
});
like image 147
generalhenry Avatar answered Nov 09 '22 16:11

generalhenry