【发布时间】:2013-03-16 11:54:55
【问题描述】:
我在 JSON 对象中有一个二维数组(称为表;)
data = {
tableID : "testTable",
table : [
[{type:'a', value:'x'},{type:'a', value:'y'},{type:'a', value:'z'}],
[{type:'a', value:'x'},{type:'a', value:'y'},{type:'a', value:'z'}],
[{type:'a', value:'x'},{type:'a', value:'y'},{type:'a', value:'z'}]
]
};
并且已经使用模板成功地用把手渲染出来了:
<table id = "{{tableID}}-table">
{{#each table}}
<tr id = "{{../tableID}}-row-{{@index}}">
{{#each this}}
<td id = "{{../../tableID}}-row-{{../index}}-col-{{@index}}">
{{this.type}}-{{this.value}}
</td>
{{/each}}
</tr>
{{/each}}
</table>
但是,在 td 标记 ID 中,我似乎无法访问父索引 {{../index}} - 行的索引。什么都没有返回:
<td id = "testTable-row--col-x">
但是,我可以访问当前上下文 {{@index}} 的索引。
有什么想法吗??
非常感谢提前!
丰富
附言使用 1.0.0-rc.3
【问题讨论】:
-
是的,这很好。这是我目前采用的方向,但希望有一些更清洁的东西;)
标签: arrays indexing this each handlebars.js