首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用zpt为每个表分配一个新的id

使用zpt为每个表分配一个新的id
EN

Stack Overflow用户
提问于 2013-05-10 23:07:26
回答 2查看 212关注 0票数 1

我使用tal:repeat语句在另一个表中生成表。遗憾的是,我不知道如何在生成时为每个表提供唯一的id。我该怎么做呢?

我试着使用:

代码语言:javascript
复制
tal:attributes="id myindex" 

代码语言:javascript
复制
tal:attributes="id string:${myindex}"

但是我不能让它工作。

示例:

代码语言:javascript
复制
<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>

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-10 23:27:34

您可以使用每个repeat循环创建的TAL repeat variable

代码语言:javascript
复制
<table tal:attributes="id string:table-${python:repeat['diagnoses'].index}" 
       class="table table-hover" style="border-style:none">

或使用路径表达式:

代码语言:javascript
复制
<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']对象,其中包含循环索引、迭代的奇偶校验(奇数或偶数)和循环计数器的偶数罗马数字版本等内容。

票数 1
EN

Stack Overflow用户

发布于 2013-05-12 21:11:59

如果Chameleon ZPT不喜欢字符串语法,您可以使用python表达式语法:

代码语言:javascript
复制
<table tal:attributes="id python:'table-' + repeat['diagnoses'].number" 
       class="table table-hover" style="border-style:none">

或者,如果您希望它是从零开始的:

代码语言:javascript
复制
<table tal:attributes="id python:'table-' + repeat['diagnoses'].index" 
       class="table table-hover" style="border-style:none">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16485358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档