Dictionary 我在使用下面的代码创建和更新字典时遇到问题
为了创建dict,我使用了以下代码:Dictionary 我在使用下面的代码创建和更新字典时遇到问题,dictionary,odoo,qweb,odoo-13,Dictionary,Odoo,Qweb,Odoo 13,为了创建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="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>
但是我得到了一个无价值的东西。为什么?
有人能帮我吗?先谢谢你
当您尝试设置值时,必须在dict
表单中指定该值
[
]
在您的示例中,无需在字典窗体的循环之前设置变量
,它将不执行任何操作
<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>