jquery模板每隔n项创建一个新行

时间:2013-01-16 00:47:19

标签: jquery-templates

来自服务器的数据结构如下:

  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,
        }
    ];

使用jquery模板,我如何创建一个每7个项目都有一个新行的表?

我想格式化

    <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>

0 个答案:

没有答案