Render table with Jade / Express.js with multiple items per row

I am trying to display a table using jade from a simple array of objects. But instead of simply rendering one line per object, I want to display three objects on each line.

<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 
+3
source share
2 answers
 objects = [[obj0, obj1, obj2], [obj3, obj4, obj5]] table thead tbody for object in objects tr for subobject in object td= subobject 
+5
source

The accepted answer technically works, but I didn’t like that you had to build the data for the logic to work. I think logic should have data. So I came up with the following:

 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] 
+6
source

Source: https://habr.com/ru/post/1240684/


All Articles