使用金字塔时,我的代码如下所示:
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:条件语句?
发布于 2017-07-26 15:30:13
在试图弄清楚这个问题的过程中,我找到了我的答案...
tal:重复语法:tal:repeat=“名称表达式”
描述:计算"expression",如果它是一个序列,则对序列中的每个项目重复一次此标记和所有子项。 " name“将设置为当前迭代中项目的值,也是repeat变量的名称。可以使用TAL路径: repeat/name访问repeat变量,该变量具有以下属性:
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">A成为nest_list_A的赋值,例如b成为a.nested_list_A的赋值,然后它将访问它们的密钥
如果键有一个值,那么tal:condition将继续正常运行,否则将在呈现时跳过。
https://stackoverflow.com/questions/45319983
复制相似问题