【问题标题】:may i get index of elder loop in html?我可以在 html 中获取老年循环的索引吗?
【发布时间】:2021-09-02 13:56:32
【问题描述】:

我有 2 个循环创建表:

{% for row in row_data %} #first loop
    {% for col, row_ in zip(column_names, row) %} #second loop
      {{row_}}
    {% endfor %}
{% endfor %}

我需要获取第一个循环索引。 {{loop.index}} 显然返回第二个循环索引。

感谢任何帮助!

UPD:

这对我有用:

{% set firstIndex = loop.index %}

【问题讨论】:

  • 那是 HTML 中的一个循环,所以我认为它是 HTML,但我可能错了
  • HTML 没有循环功能。它只是一种标记语言。你在用 Django 吗?
  • 对不起,回答太长了。我正在使用烧瓶。

标签: html loops flask indexing


【解决方案1】:

将第一个循环索引设置为变量:

{% for row in row_data %} #first loop
    {% set firstIndex = loop.index %}

    {% for col, row_ in zip(column_names, row) %} #second loop
      {{row_}}
    {% endfor %}
{% endfor %}

【讨论】:

    猜你喜欢
    • 2016-03-10
    • 1970-01-01
    • 2012-07-28
    • 2011-08-17
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 2010-11-15
    • 2017-07-28
    相关资源
    最近更新 更多