2017-07-26 59 views
1

與金字塔的工作,我的代碼看起來是這樣的:TAL嵌套的字典語法

class PageData: 
    @staticmethod 
    def create_data(): 
     return [ 
      { 
       'key_1A': 'info1A', 
       'key_2A': 'info2A', 
       'nested_list_A': [ 
        {'nested_key1A': 'nested_val1A'}, 
        {'nested_key2A': 'nested_val2A'}, 
       ], 
      }, 
      { 
       'key_1A': 'info1B', 
       'key_2A': 'info2B', 
       'nested_list_B': [ 
        {'nested_key1B': 'nested_val1B'}, 
        {'nested_key2A': 'nested_val2A'}, 
       ], 
      }, 
      ] 

而且我的HTML頁面的代碼如下所示:

<span tal:condition="nested_key1A">  Open  </span> 
<span tal:condition="not nested_key1A"> Closed </span> 

什麼是正確的語法來引用nested_key?對於tal:條件語句?

回答

0

在試圖弄清楚這一點,我發現我的答案...

TAL:重複 語法:TAL:重複= 「名錶述」

說明:評估 「表達」,如果它是一個序列,爲序列中的每個項目重複此標記和所有孩子一次。 「名稱」將被設置爲當前迭代中項目的值,也是重複變量的名稱。重複變量是使用TAL路徑訪問:重複/名稱,並具有以下性質:

https://www.owlfish.com/software/simpleTAL/tal-guide.html

<div tal:repeat="a nest_list_A"> 
<div tal:repeat="b a.nest_list_A"> 
<span tal:condition="b.nested_key1A"> 

一個成爲nest_list_A分配例如 b換成用於a.nested_list_A分配哪然後將訪問他們的密鑰

如果有一個值的關鍵,然後tal:條件將繼續正常,否則它會跳過,而渲染。