简体   繁体   中英

How to display value of grouped objects at jade template in javascript node.js

Based on this How to split array dynamically based on single value in JavaScript Node.js i created object with Arrays, and i can display name of each array by this:

- each item in Object.keys(groupedData)
         li= item

result is:

* Fruit
* Sport
* Kitchen

However how can I display value of each array in diffrent tables? eg. 表的例子

I don't know how to take any value from array?

I thought about this li= item.array[0].tag but it doesn't work.


@EDIT

If I use:

 - each val, key in groupedData
         li #{JSON.stringify(val)}

I can display values, result at view:

[{"name":"Apple","tag":"Fruit","price": 2},
{"name":"Kiwi","tag":"Fruit","price": 1}]

But how can i put this to table?

Here's a small example that you can see working in this codepen

- var groupedData = {'X': [{'a': 'x0', 'b': 'x1'},{'a': 'xx0', 'b': 'xx1'}], 'Y': [{'a': 'y0', 'b': 'y1'},{'a': 'yy0', 'b': 'yy1'}], 'Z': [{'a': 'z0', 'b': 'z1'},{'a': 'zz0', 'b': 'zz1'}]}
- each grp in Object.keys(groupedData)
  h1= grp
  table
    thead
      - each val, index in groupedData[grp][0]
        th= index
    - each subgrp in groupedData[grp]
      tr
        - each val in subgrp
          td= val

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