我正在尝试为Django数据库中的项目列表创建Bootstrap手风琴。呈现时,当前我的代码将仅折叠并在for循环的第一项上展开。对于其他项目,当我单击这些项目时,第一个项目会展开/折叠,而不是正在单击的项目。请寻找解决方案。
<div class="panel-group">
<div class="panel panel-default">
{% for issue in issues %}
<div class="panel-heading">
<div class="panel-title">
<a data-toggle="collapse" data-target="#collapse1"><h3><i class="fas fa-chevron-down"></i> {{ issue.title }}</h3></a>
</div>
</div>
<div id="collapse1" class="panel-collapse collapse">
<p><strong>Type: </strong>{{ issue.type }}</p>
<p class="issue-description"><strong>Description: </strong>{{ issue.description }}</p>
<p><strong>Requested By: </strong>{{ issue.requested_by }}</p>
<p><strong>Date Created: </strong>{{ issue.date_created }}</p>
<p><strong>Status: </strong>{{ issue.status }}</p>
<p><strong>Date Completed: </strong>{{ issue.completed_date }}</p>
<p><strong>Upvotes: </strong>{{ issue.upvotes }}</p>
</div>
{% endfor %}
</div>
</div>
答案 0 :(得分:1)
提供诸如<div id="collapse-{{ issue.pk }}" class="panel-collapse collapse">
之类的div唯一ID,并在data-target
中引用它:data-target="#collapse-{{ issue.pk }}"