获取外循环的循环索引 [英] Get loop index of outer loop
本文介绍了获取外循环的循环索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在jinja中,变量loop.index包含当前正在运行的循环的迭代次数.
In jinja, the variable loop.index holds the iteration number of the current running loop.
当我有嵌套循环时,如何在内部循环中获得外部循环的当前迭代?
When I have nested loops, how can I get in the inner loop the current iteration of an outer loop?
推荐答案
将其存储在变量中,例如:
Store it in a variable, for example:
{% for i in a %}
{% set outer_loop = loop %}
{% for j in a %}
{{ outer_loop.index }}
{% endfor %}
{% endfor %}
这篇关于获取外循环的循环索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文