Asi*_*ial 3 extjs sencha-touch
我有一个表格,每行都有一个复选框.我无法选择多个复选框.以下是ref的Item Tpl的代码:
+'<tpl for="rows">'
+ '<tr>'
+'<tpl for="columns">'
+'<tpl if="dataIndex== \'checkbox\'">'
+ '<td><input type="checkbox" id="checkbox{#}" class="regular-checkbox" /><label class="m0" for="checkbox{#}"></label></td>'
+'<tpl else>'
+'<td><p>{value}</p></td>'
+'</tpl>'
+'</tpl>'
+'</tr>'
+'</tpl>'
Run Code Online (Sandbox Code Playgroud)
我有一个问题是获取项目Tpl中的行循环的索引,以便为每个复选框提供唯一的ID.任何人都可以指导我锄头得到它吗?
Ext.XTemplate支持逐字块(语法{% ... %}).这些块中包含的任何代码都将直接插入到生成的模板代码中.
因此,在父循环中,您可以在存储当前索引的位置声明自己的局部变量{% var parentIndex = xindex; %}.然后在子循环中,您可以获得此变量的值{[parentIndex]}
您的完整模板代码应为:
'<tpl for="rows">'
+'{% var parentIndex = xindex; %}'
+ '<tr>'
+'<tpl for="columns">'
+'<tpl if="dataIndex== \'checkbox\'">'
+ '<td><input type="checkbox" id="checkbox{[parentIndex]}" class="regular-checkbox" /><label class="m0" for="checkbox{[parentIndex]}"></label></td>'
+'<tpl else>'
+'<td><p>{value}</p></td>'
+'</tpl>'
+'</tpl>'
+'</tr>'
+'</tpl>'
Run Code Online (Sandbox Code Playgroud)