我感到无助。我想用 jquery 模板插件构建一个表,然后用响应中的数据填充表,如下所示:
[
[
{Row:0,Col:0},
{Row:0,Col:1},
{Row:0,Col:2},
{Row:0,Col:3},
{Row:0,Col:4},
{Row:0,Col:5},
{Row:0,Col:6}
],
[
{Row:1,Col:0},
{Row:1,Col:1},
{Row:1,Col:2},
{Row:1,Col:3},
{Row:1,Col:4},
{Row:1,Col:5},
{Row:1,Col:6}
]
]
所以该表应该是每行 2 行 7 列。
这是我坚持的代码:
$('#trTemplate').tmpl(result.d).appendTo('#containerTable');
<script id="trTemplate" type="text/x-jquery-tmpl">
{{each $data}}
{{if $index < 2}}
<tr>
{{tmpl($value) "#tdTemplate"}}
</tr>
{{/if}}
{{/each}}
</script>
<script id="tdTemplate" type="text/x-jquery-tmpl">
{{each $data}}
<td>${Col}</td>
{{/each}}
</script>
<table id="containerTable">
</table>
我尝试了不同的方法,改变了工作正常的数据源的外观,尝试在没有模板的情况下构建表,但我真的需要知道如何构建具有此类数据源并使用模板的表?谢谢您的帮助。