使用Jade,NodeJS,Express的动态html页面

时间:2022-12-05 13:44:34

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.

我有一个大的json对象,其中包含从redis密钥库中检索的示例电子表格中的单元格数据。我想在jade模板中以html表格式显示它。但就目前而言,我只能将其显示为json字符串。

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

我也不清楚如何使用jade / express生成动态网页。

Sample JSON string am trying to pass:

我尝试传递的示例JSON字符串:

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

It is data from an excel spreadsheet.

它是来自Excel电子表格的数据。

Please help me to clear this doubt.

请帮我澄清这个疑问。

1 个解决方案

#1


17  

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
});

#1


17  

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
});