我应该如何使用ejs垂直渲染表格?

Che*_*ian 3 javascript ejs embedded-javascript

我有一个如下数组:

quotation: [{
              "dimension" : 0,
              "currency": "RMB",
              "quantity": "100",
              "price": "3",
              "factory": "rx"},
            {
              "dimension" : 0,
              "currency": "RMB",
              "quantity": "200",
              "price": "4",
              "factory": "rx"},
           {
              "dimension" : 1,
              "currency": "RMB",
              "quantity": "100",
              "price": "3",
              "factory": "rx"},
           {
              "dimension" : 1,
              "currency": "RMB",
              "quantity": "200",
              "price": "5",
              "factory": "rx"},
            {
              "dimension" : 0,
              "currency": "RMB",
              "quantity": "100",
              "price": "1.2",
              "factory": "hsf"},
            {
              "dimension" : 0,
              "currency": "RMB",
              "quantity": "200",
              "price": "2.4",
              "factory": "hsf"},
           {
              "dimension" : 1,
              "currency": "RMB",
              "quantity": "100",
              "price": "3",
              "factory": "hsf"},
           {
              "dimension" : 1,
              "currency": "RMB",
              "quantity": "200",
              "price": "4.5",
              "factory": "hsf"}]
Run Code Online (Sandbox Code Playgroud)

我该如何使用ejs转入下表?

<table>
   <tr>
      <th>Dimension</th><th>Quantity</th><th>Factory: rx</th><th>Factory: hsf</th>
   </tr>
   <tr>
      <td>0</td><td>100</td><td>3</td><td>1.2</td>
   </tr>
   <tr>
      <td>0</td><td>200</td><td>4</td><td>2.4</td>
   </tr>
   <tr>
      <td>1</td><td>100</td><td>3</td><td>3</td>
   </tr>
   <tr>
      <td>1</td><td>200</td><td>5</td><td>4.5</td>
   </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

我必须确保价格来自正确的工厂.我认为如果html允许我逐列定义表,这个问题很容易.但是html表只允许我按行进行.

非常感谢您的帮助.

Ale*_* T. 7

<table>
   <tr>
      <th>Dimension</th><th>Quantity</th><th>Factory: rx</th>
   </tr>

   <% for (var i = 0; i < quotation.length; /* I save the data in a variable 'quotation', I don't know how you named your variable  */  i++) { %>
    <tr>
      <td><%= quotation[i].dimension %></td>
      <td><%= quotation[i].quantity %></td>
      <td><%= quotation[i].factory %></td>
    </tr>    
   <% } %>
</table>
Run Code Online (Sandbox Code Playgroud)