首页 > 解决方案 > 我无法使用以下代码创建和更新字典

问题描述

为了创建一个字典,我使用了以下代码:

<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>

但我得到了一个无价值。为什么?任何人都可以帮助我吗?提前谢谢..

标签: dictionaryodooqwebodoo-13

解决方案


沙欣沙乌默尔

dict当您尝试设置 [ <t t-set="variable" t-value=""/>]时,您必须在表单中指定值。

在您的示例中,无需使用form 设置variablebefore循环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>

推荐阅读