首页 > 解决方案 > 如何在odoo中的模板标签内的foreach中给出当前迭代

问题描述

如何在foreach不为库存迭代次数创建新变量的情况下知道内部模板中的当前迭代次数?我不能在 odoo 文档中使用示例https://www.odoo.com/documentation/11.0/reference/qweb.html#reference-qweb 例如:

$as_all
    the object being iterated over
$as_value
    the current iteration value, identical to $as for lists and integers, but for mappings it provides the value (where $as provides the key)
$as_index
    the current iteration index (the first item of the iteration has index 0)
$as_size
    the size of the collection if it is available
$as_first
    whether the current item is the first of the iteration (equivalent to $as_index == 0)
$as_last
    whether the current item is the last of the iteration (equivalent to $as_index + 1 == $as_size), requires the iteratee’s size be available

标签: odoo

解决方案


您可能错过了文档中的这一部分:

$as将替换为传递给的名称t-as

例子:

<t t-foreach="some_list" t-as="var_name">
  <p> I'm in loop <t t-esc="var_name_index"/></p>
</t>

推荐阅读