1

使用 Pyramid,我的代码如下所示:

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:condition 语句?

4

1 回答 1

0

在试图弄清楚这一点时,我找到了答案......

tal:repeat 语法:tal:repeat="名称表达式"

描述:评估“表达式”,如果它是一个序列,则对序列中的每个项目重复此标签和所有子项一次。 “名称”将设置为当前迭代中项目的值,也是重复变量的名称。可以使用 TAL 路径访问重复变量:repeat/name,并具有以下属性:

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 将照常继续,否则将在渲染时跳过。

于 2017-07-26T07:30:12.713 回答