javascript - Attach Div to Th id / django forloop counter issue
问题描述
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
解决方案
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}}
推荐阅读
- amazon-web-services - AWS Cloudformation 模板:哪个部分?
- r - 在 R 中加入跨国表
- angular - 我如何在 Angular 6 中预览文件(文档和图像)?
- database - 迁移自引用外键问题
- c - 生成原始比特流作为输出到另一个软件中的管道
- reporting-services - 将 SSRS 报告和数据驱动订阅从 2008R2 迁移到 2012
- javascript - 如何获取子组件的节点/引用?
- javascript - 不断从字段中获取数据并插入到div中
- python - Python 麻烦保存几个池处理的文件
- omnet++ - 我如何将排队库链接到项目