jquery template create new row every nth item

梦想的初衷 提交于 2020-01-05 07:51:13

问题


data from server structured like:

  var projects= [
        { 
          name: 'project 1', 
          hours: 1,
        },
        { 
          name: 'project 1', 
          hours: 2,
        },
        { 
          name: 'project 1', 
          hours: 3,
        },
        { 
          name: 'project 1', 
          hours: 4,
        },
        { 
          name: 'project 1', 
          hours: 5,
        },
        { 
          name: 'project 1', 
          hours: 6,
        },
        { 
          name: 'project 1', 
          hours: 7,
        },
        { 
          name: 'project 2', 
          hours: 1,
        },
        { 
          name: 'project 2', 
          hours: 2,
        },
        { 
          name: 'project 2', 
          hours: 3,
        },
        { 
          name: 'project 2', 
          hours: 4,
        },
        { 
          name: 'project 2', 
          hours: 5,
        },
        { 
          name: 'project 2', 
          hours: 6,
        },
        { 
          name: 'project 2', 
          hours: 7,
        }
    ];

With jquery template how do I created a table with a new row every 7th item?

I want to format like

    <table>
    <tr>
<td>project 1
    <td>hours 1</td>
    <td>hours 2</td>
    <td>hours 3</td>
    <td>hours 4</td>
    <td>hours 5</td>
    <td>hours 6</td>
    <td>hours 7</td>
    </tr>
    <tr>
    <td>project 2</td>
    <td>hours 1</td>
    <td>hours 2</td>
    <td>hours 3</td>
    <td>hours 4</td>
    <td>hours 5</td>
    <td>hours 6</td>
    <td>hours 7</td>
    </tr>
    </table>

来源:https://stackoverflow.com/questions/14349672/jquery-template-create-new-row-every-nth-item

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