我使用tal:repeat语句在另一个表中生成表。遗憾的是,我不知道如何在生成时为每个表提供唯一的id。我该怎么做呢?
我试着使用:
tal:attributes="id myindex" 和
tal:attributes="id string:${myindex}"但是我不能让它工作。
示例:
<table id="tableIngrepen" class="table">
<thead class="header">
<tr>
<th>Header1</th>
<th tal:repeat="procedur_headers Procedur_Headers" tal:content="procedur_headers" > </th>
</tr>
</thead>
<tr tal:repeat="diagnoses Diagnoses">
<div tal:define="myindex python:repeat['diagnoses'].index">
<td ><input type='text' id="dz_code" readonly></input></td> <!-- onfocus="rijencolom($(this).parent().children().index($(this)),$(this).parent().parent().children().index($(this).parent()))" -->
<td colspan="5">
<table tal:attributes="id myindex" class="table table-hover" style="border-style:none">
<thead class="header">
<tr>
<th tal:repeat="procedur_headers Procedur_Headers" tal:content="procedur_headers" style="display:none"> </th> <!-- style="display:none"-->
</tr>
</thead>
<tr tal:repeat="list_procedur List_Procedur[myindex]">
<td><input type='text' ></input></td>
</tr>
<tr>
<td><input type='text' ></input></td>
<td ><input type='text'></input></td>
<td><input type='text' ></input></td>
<td><input type='text' ></input></td>
</tr>
</table>
</td>
</div>
</tr>
发布于 2013-05-10 23:27:34
您可以使用每个repeat循环创建的TAL repeat variable:
<table tal:attributes="id string:table-${python:repeat['diagnoses'].index}"
class="table table-hover" style="border-style:none">或使用路径表达式:
<table tal:attributes="id string:table-${path:repeat/diagnoses/index}"
class="table table-hover" style="border-style:none">根据Chameleon的配置,您可以省略path:或python:前缀;无论哪一个是缺省表达式类型。页面模板默认为path:表达式,变色龙为python:,但通常Plone集成将其切换为path:以保持兼容性。
repeat映射为每个循环变量包含一个特殊的对象;您的循环使用名称myindex,因此有一个repeat['diagnoses']对象,其中包含循环索引、迭代的奇偶校验(奇数或偶数)和循环计数器的偶数罗马数字版本等内容。
发布于 2013-05-12 21:11:59
如果Chameleon ZPT不喜欢字符串语法,您可以使用python表达式语法:
<table tal:attributes="id python:'table-' + repeat['diagnoses'].number"
class="table table-hover" style="border-style:none">或者,如果您希望它是从零开始的:
<table tal:attributes="id python:'table-' + repeat['diagnoses'].index"
class="table table-hover" style="border-style:none">https://stackoverflow.com/questions/16485358
复制相似问题