dictionary - 我无法使用以下代码创建和更新字典
问题描述
为了创建一个字典,我使用了以下代码:
<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-set="variable" t-value=""/>
]时,您必须在表单中指定值。
在您的示例中,无需使用form 设置variable
before循环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>
推荐阅读
- assembly - EXTRN 函数调用问题有没有办法知道是什么原因造成的?
- android - 当应用程序处于后台时,Firebase 通知未在 Android 应用程序中正确显示?
- html - 友好的 URL 类型 Onepage
- python - 在python上将两个df cols转换为dict
- java - 致命异常:java.lang.RuntimeException 在类 com.suman_miazi.e_exam.utils.f 上找不到要序列化的属性
- swiftui - 在 DragGesture onChanged 后重新初始化视图
- node.js - router.patch 返回 404“未找到”
- vb.net - 警告我的 Async 函数实际上是在 VB.NET 中同步运行
- django - 我在项目中创建了两个模板,在应用程序中创建了另一个模板,错误即将到来模板不存在
- c# - 根据字典 C# 的内容调用函数