【问题标题】:tal nested dictionary syntaxtal 嵌套字典语法
【发布时间】:2017-07-26 15:30:12
【问题描述】:

使用 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 语句?

【问题讨论】:

    标签: python html chameleon tal


    【解决方案1】:

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

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

    说明:评估“表达式”,如果是序列,则对序列中的每个项目重复此标记和所有子项一次。 “name”将设置为当前迭代中item的值,也是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 的分配,然后将访问它们的键

    如果 key 有值,则 tal:condition 会照常继续,否则会在渲染时跳过。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-29
      • 1970-01-01
      • 2018-01-29
      • 2021-12-20
      • 2012-01-29
      • 2018-05-31
      • 1970-01-01
      相关资源
      最近更新 更多