【发布时间】:2019-02-27 21:58:22
【问题描述】:
我已经在 django 模板中发布了一个表的代码,该模板是使用 views.py 中的数组动态生成的。我添加了一个 bootstrap4 折叠,它在单击 V 形按钮时运行。但是,它显示了所有隐藏的折叠,而不仅仅是该给定行的可折叠数据(参见下面的 img)。
我知道我可以动态设置 id,但我没有任何运气将函数传递给“data-target”属性。
<table class="table table-hover">
<thead class>
<tr>
<th style="width:5%"></th>
<th>Sample</th>
<th>Reference</th>
<th>Cost</th>
<th>Sum</th>
</tr>
</thead>
<tbody>
<div class="container" id="accordion">
<div class="card">
{% for r in result %}
<tr>
<td>
<button type="button" class="fa fa-chevron-right rotate" data-toggle="collapse"
data-target="#demo" onclick="">
</button>
</td>
<td> {{ r.split.0 }} </td> <!-- sample word -->
<td> {{ r.split.2 }}</td> <!-- ref word -->
<td> {{ r.split.4 }}</td> <!-- cost -->
<td> {{ r.split.3 }}</td> <!-- sum -->
</tr>
<tr>
<td id="demo" class="collapse" colspan="5" >
<!-- COLLAPSE CONTENT -->
</td>
</tr>
{% endfor %}
</div>
</div>
</tbody>
</table>
【问题讨论】:
-
仔细阅读documentation 应该可以帮助您在按钮的
data-target属性中生成正确的值,对应于可折叠元素标签中id或class属性的正确值.
标签: django django-templates bootstrap-4