2013-05-10 38 views
1

所以我使用tal:repeat語句在另一個表內生成表。 可悲的是,我不知道如何在生成時爲每個表提供唯一的ID。我怎樣才能做到這一點?給每個表使用zpt的新ID使用zpt

我試圖使用方法:

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> 

回答

1

可以使用每個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"> 

根據如何配置變色龍,您可以省略前綴path:python:;無論哪一個是默認的表達式類型。 Pagetemplates默認爲path:表達式,變色龍爲python:,但通常情況下,Plone集成切換到path:以保持兼容性。

repeat映射包含每個循環變量的特殊對象;你的循環使用名稱myindex,所以有一個repeat['diagnoses']對象,其中包含循環索引,迭代的奇偶校驗(奇數或偶數),甚至羅馬數字版本的循環計數器。

+0

是的語法好嗎?它不是'table - $ {repeat/myindex/index}'? – 2013-05-10 16:03:21

+0

@keul:啊,是的。這是變色龍用於* Plone *;默認變色龍使用Python表達式,但Plone集成切換到路徑表達式。 – 2013-05-10 16:04:04

+0

所以我想我畢竟走在了正確的軌道上,感謝這種消除,這超出了我的期望。然而,我認爲我使用默認的變色龍zpt,因爲當我使用代碼時,我提供了以下錯誤:TypeError:不支持的操作數類型爲/:'RepeatDict'和'callableint'==>表達式:「string :表 - $ {重複/ myindex /指數}」。 – GertV 2013-05-10 16:17:37

0

如果變色龍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">