如何通过mustache.js在2d表中呈现数据?

时间:2013-12-19 07:36:11

标签: javascript rendering mustache

我的数据由100个或这样的行组成。

{"data":[
{"country":["AD"], "number":["41","2","33","56","45","50","57","68"]},
{"country":["AE"], number":["5","9","2","19","7","11","6","1"]}
]}

我想以二维数组形式呈现它

<tr>
<td>Country</td>
<td>Value  of number on date1</td>
<td>Value of number on date2</td>
<td>Value  of number on date3</td>
<td>Value of number on date4</td>
<td>Value  of number on date5</td>
<td>Value of number on date6</td>
<td>Value  of number on date7</td>
</tr>

我使用的脚本模板 -

<tbody>
    {{#data}}
    <tr> 
    <td>{{country}}</td>
    {{#number}}
    <td>{{number}}</td>
    {{/number}}
    </tr>
    {{/data}}
    </tbody>

只有国家正在呈现而不是数字。有人可以解释一下我做错了吗?

1 个答案:

答案 0 :(得分:1)

您需要在{{# number }}部分内使用隐式迭代器标记:{{ . }}

{{# number }}
  <td>{{ . }}</td>
{{/ number }}