如何在模板中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
答案 0 :(得分:1)
您可能错过了from the docs这一部分:
$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>