简体   繁体   English

引导程序行为什么不折叠/展开?

[英]Why is are the bootstrap rows not collapsing/expanding?

I have a table that displays nested data. 我有一个显示嵌套数据的表。 The data looks something as follows: 数据如下所示:

Objective 1
    Objective 1.1
        Objective 1.1.1
    Objective 1.2
        Objective 1.2.1
Objective 2

The data is to be displayed in a table as follows: 数据将在表中显示如下: 在此处输入图片说明

The requirement is that, when clicking on Objective 1, that the child rows (Objective 1.1 and Objective 1.2) appear. 要求是,在单击目标1时,将出现子行(目标1.1和目标1.2)。 Then, when either Objective 1.1 or Objective 1.2 is clicked, that the relevant grandchild row appears (Objective 1.1 --> Objective 1.1.1). 然后,当单击“目标1.1”或“目标1.2”时,将出现相关的孙行(“目标1.1->目标1.1.1”)。

I use Python, Flask and Bootstrap for this project, and I want to perform this task purely in Bootstrap if possible. 我为此项目使用Python,Flask和Bootstrap,并且如果可能的话,我希望仅在Bootstrap中执行此任务。

My current HTML is as follows: 我当前的HTML如下:

<table class="table">
<thead>
<tr>
    <th>Primary Objectives</th>
    <th>Secondary Objectives</th>
    <th>Tertiary Objectives</th>
    <th>Editing Tools</th>
</tr>
</thead>

<tbody>
{% for node in all_nodes %}
<tr class="clickable" data-toggle="collapse" id="{{ node[0][1] }}" data-target=".{{ node[0][1] }}collapsed">
    <!-- objective tree -->
    <td class="text-left">{{ node[0][0] }}</td>
    <td class="text-left"></td>
    <td class="text-left"></td>

    <!-- Editing tools -->
    <td><a href="/edit/{{ node[0][1] }}" class="fa fa-edit"
           title="Edit Objective"></a>
        <div class="fa fa-circle-thin"></div>
        <a href="/deleteobjective/{{ node[0][1] }}" class="fa fa-exclamation-triangle"
           title="Delete User"></a>
    </td>
</tr>
{% for node2 in node[1] %}
<tr class="clickable collapse out {{ node[0][1] }}collapsed" id="{{ node2[0][1] }}" data-toggle="collapse"
    data-target=".{{ node2[0][1] }}collapsed">
    <!-- objective tree -->
    <td class="text-left"></td>
    <td class="text-left">{{ node2[0][0] }}</td>
    <td class="text-left"></td>

    <!-- Editing tools -->
    <td><a href="/edit/{{ node2[0][1] }}" class="fa fa-edit"
           title="Edit Objective"></a>
        <div class="fa fa-circle-thin"></div>
        <a href="/deleteobjective/{{ node2[0][1] }}" class="fa fa-exclamation-triangle"
           title="Delete User"></a>
    </td>
</tr>
{% for node3 in node2[1] %}
<tr class="collapse out {{ node2[0][1] }}collapsed">
    <!-- objective tree -->
    <td class="text-left"></td>
    <td class="text-left"></td>
    <td class="text-left">{{ node3[0] }}</td>

    <!-- Editing tools -->
    <td><a href="/edit/{{ node3[1] }}" class="fa fa-edit"
           title="Edit Objective"></a>
        <div class="fa fa-circle-thin"></div>
        <a href="/deleteobjective/{{ node3[1] }}" class="fa fa-exclamation-triangle"
           title="Delete User"></a>
    </td>
</tr>
{% endfor %}
{% endfor %}
{% endfor %}
</tbody>

The table displays correctly and my code works when clicking Objective 1, but when clicking Objective 1.1 or Objective 1.2 the grandchild rows do not expand. 该表正确显示,并且在单击“目标1”时我的代码可以工作,但是在单击“目标1.1”或“目标1.2”时,子级行不会展开。

Please help! 请帮忙!

When printing HTML for the Objective XX, you have: 为目标XX打印HTML时,您具有:

data-target="#.{{ node2[0][1] }}collapsed"

but you should have 但是你应该有

data-target=".{{ node2[0][1] }}collapsed"

The selector is not finding the element to collapse. 选择器未找到要折叠的元素。

Hope it works after fixing this :D 希望在修复此问题后:D

Ok, so after hours of head scratching I found the problem! 好的,所以经过数小时的头部抓挠后,我发现了问题所在!

The program generates unique id numbers for each row that relates to the next row's data-target, using the given objective's unique code. 该程序使用给定目标的唯一代码为与下一行数据目标相关的每一行生成唯一的ID号。 The data-target is expressed as: 数据目标表示为:

data-target=".{{ node[0][1] }}collapsed"

The resulting HTML looks like this: 生成的HTML如下所示:

 <tr class="clickable collapse out obj1collapsed" id="obj1.1"
                data-toggle="collapse"
                data-target=".obj1.1collapsed">

Notice that second period in the data-target? 注意数据目标中的第二个期间吗? That is what caused the problem! 那是造成问题的原因! When I removed it the program worked beautifully! 当我删除它时,程序运行得很漂亮!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM