收起时展开按钮消失

时间:2019-03-29 08:51:55

标签: html css angularjs user-interface

我下面的代码在每行中都有一个按钮,它们具有两种功能,它们是该按钮所在的特定行的展开和折叠。

<div class="">
    <ul>
        <li
          ng-repeat="nav in ciRelationshipHierarchyBySection track by $index"
          style="background:none; padding:0 10px;margin:5px;"
          class="nav nav-list panel-collapse collapse in"
          id="networkDevicesCollapsePanel_{{$index}}"
        >
            <div
              ng-show="ciAttributesCount"
              id="collapsebutton_{{$index}}"
              data-toggle="collapse"
              data-target="#networkDevicesCollapsePanel_{{$index}}"
              class="nodisp expandcollapse no-print">
                <i class="glyphicon glyphicon-minus"></i>Collapse/expand
            </div>
            <a
              style="cursor:pointer; padding: 2px 12px;"
              ng-click="showNetworkDevices(nav.IdentificationSourceId)">
                {{nav.IdentifySourceName}}
            </a>
            <span style="padding: 2px 12px;">Source Id: {{nav.IdentificationSourceId}}</span>
            <br />
            <span style="padding: 2px 12px;">Data Source: {{nav.DataSource}}</span>
            <br />
            <span style="padding: 2px 12px;">Create New: {{nav.IsCreateNew}}</span>
            <br />
        </li>
    </ul>
</div>

我的问题是,由于按钮位于同一行中,因此按钮也将折叠并且无法看到展开。

如何解决这个问题?

按钮点击事件如下所示:

$("#expandbutton1").hide();

        $("#expandbutton1").click(function () {
            $('#networkDevicesLinks div.panel-collapse').addClass('in').css("height", "");
            $("#expandbutton1").hide();
            $("#collapsebutton1").show();

            $('a[data-toggle="collapse"]').each(function (index) {
                $(this).find("i").removeClass("fa-plus-square-o").addClass("fa-minus-square-o");
            });
        });

        $("#collapsebutton1").click(function () {
            $('#networkDevicesLinks div.panel-collapse').removeClass('in');
            $("#expandbutton1").show();
            $("#collapsebutton1").hide();

            $('a[data-toggle="collapse"]').each(function (index) {
                $(this).find("i").removeClass("fa-minus-square-o").addClass("fa-plus-square-o");
            });
        });
    });

1 个答案:

答案 0 :(得分:1)

考虑将可折叠面板插入li标签的内部子项中:

<ul>
    <!-- remove anything make the li collapsible -->
    <li
      ng-repeat="nav in ciRelationshipHierarchyBySection track by $index"
      style="background:none; padding:0 10px;margin:5px;"
      class="nav nav-list"
    >
        <div
          ng-show="ciAttributesCount"
          id="collapsebutton_{{$index}}"
          data-toggle="collapse"
          data-target="#networkDevicesCollapsePanel_{{$index}}"
          class="nodisp expandcollapse no-print">
            <i class="glyphicon glyphicon-minus"></i>Collapse/expand
        </div>
        <!-- new collapsible tag inside the li -->
        <div
          class="panel-collapse collapse in"
          id="networkDevicesCollapsePanel_{{$index}}"
        >
            <a
              style="cursor:pointer; padding: 2px 12px;"
              ng-click="showNetworkDevices(nav.IdentificationSourceId)">
                {{nav.IdentifySourceName}}
            </a>
            <span style="padding: 2px 12px;">Source Id: {{nav.IdentificationSourceId}}</span>
            <br />
            <span style="padding: 2px 12px;">Data Source: {{nav.DataSource}}</span>
            <br />
            <span style="padding: 2px 12px;">Create New: {{nav.IsCreateNew}}</span>
            <br />
        </div>
    </li>
</ul>