首页 > 解决方案 > Attach Div to Th id / django forloop counter issue

问题描述

enter image description here


I have a table that looks like this:


{% for object in object_list %}
<tr>
    {% for object in object_list %}
        <td id="destination">{{ forloop_counter }}</td>
    {% endfor %}
</tr>
{% endfor %}

and I am using this function to attach the bar to the th.


 function MoveDiv() {
        var fragment = document.createDocumentFragment();
        fragment.appendChild(document.getElementById('bar'));
        document.getElementById('destination').appendChild(fragment);
    }

I wanted to use the foorloop counter to assign an id to each cell.

But the forloop counter populates the cells of the same column with the same id.

What else can I try to assign a unique id to each cell?

Thank you

标签: javascripthtmlcssdjango

解决方案


You can try combining the counter values of the two loops to generate a unique value.

You can access the outer loop with:

{{forloop.parentloop.counter}}

推荐阅读