为了创建dict,我使用了以下代码:
<t t-set="count" t-value="dict()"/>
<t t-foreach="count_obj" t-as="ob">
<t t-set="count" t-esc="count.update({ob.id: ob.name})"/>
</t>
但我得到了一个无价值。为什么?有人能帮我吗?提前谢谢。。
沙欣沙夏季
当您尝试设置值[<t t-set="variable" t-value=""/>
]时,必须以dict
形式指定值。
在您的示例中,不需要在循环之前设置variable
,使用dictionary
形式,它将不执行任何操作。
<t t-foreach="count_obj" t-as="ob">
<t t-set="count" t-value="{ob.id: ob.name}"/> <!-- Set the Value in form of dictionar -->
<span t-esc="count"/>
</t>