Render table with Jade/Express.js having multiple elements per row

女生的网名这么多〃 提交于 2019-12-01 07:08:48

问题


I'm trying to render a table using jade from a simple array of objects. But instead of simply rendering one row per object, I want to render three objects on each row.

<table>
  <thead>...</thead>
  <tbody>
    <tr>
      <td>obj0</td>
      <td>obj1</td>
      <td>obj2</td>
    </tr>
    <tr>
      <td>obj3</td>
      <td>obj4</td>
      <td>obj5</td>
    </tr>
    ...
  </tbody>
</table

回答1:


objects = [[obj0, obj1, obj2], [obj3, obj4, obj5]]

table
  thead
  tbody
  for object in objects
    tr
      for subobject in object
        td= subobject



回答2:


Accepted answer technically works, but I didn't like that you had to construct the data so that the logic works. I think that the logic should accomodate the data. As such, I came up with this:

objects = [obj0, obj1, obj2, obj3, obj4, obj5]

table
  thead
  tbody
    - var columns = 3
    - for (var i = 0; i < objects.length; i=i+columns)
      tr
        - for (var j = 0; j < columns && i+j < objects.length; j++)
          td=objects[i+j]


来源:https://stackoverflow.com/questions/11180096/render-table-with-jade-express-js-having-multiple-elements-per-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!