代码之家  ›  专栏  ›  技术社区  ›  user944513

如何在angularjs中使行折叠

  •  0
  • user944513  · 技术社区  · 7 年前

    我在试图扩张和瓦解我的 section 但不能得到正确的结果。

    首先我做一个简单的演示 collapse/expand https://plnkr.co/edit/Rxc3As7qI65rajp6Wv47?p=preview 上面的例子很好用 see first-row collapse/expand .

    我在另一个例子中使用了同样的概念 table 有 different sections 例子 GENERAL_INFORMATION 和 User INFORMATION . 我想 折叠/展开 这些部分。

    这是我的密码 http://plnkr.co/edit/0ME41KD2jkbbYZzJYf6C?p=preview

    <tr ng-repeat="(key, value) in name">
        <uib-accordion>
          <div uib-accordion-group class="panel-default" is-open="status.open">
              <uib-accordion-heading>
    
                <td ng-if="value.type == 'LABEL'" colspan="2" style="background: #777; color: white;">
                    {{key}}
                </td>
              </uib-accordion-heading>
          </div>
       </uib-accordion>
    
        <td ng-if="value.type == 'FIELD'">{{key}}
            <span ng-if="value.required">
                <sup class="required">*</sup>
            </span>
        </td>
        <td ng-if="value.type == 'FIELD'"
        >
            {{value.value}}
        </td>      
    </tr>
    

    有什么更新吗?

    0 回复  |  直到 7 年前
        1
  •  0
  •   Gone    7 年前

    使用基本的AngularJS技术,可以通过使用 ng-if 用一个 show

    如果有多个标题和内容组合,则可以使用 显示 .

    这个片段展示了基本技术。但是,您可能希望将行为封装在一个指令中,例如 uib-accordion 做。

    angular.module('myApp', ['ngAnimate'])
      .controller('myController', ['$scope', function($scope) {
        $scope.show = [];
        $scope.show[0] = false;
        $scope.show[1] = false;
    
        $scope.toggle = function(index) {
          $scope.show[index] = !$scope.show[index];
        };
      }]);
    table {
      width: 100%;
    }
    
    .heading {
      height: 48px;
      background-color: #555;
      color: #fff;
      cursor: pointer;
    }
    
    .content {
      background-color: #eee;
      height: 150px;
      transition: all 3s ease-out;
    }
    
    
    /* The starting CSS styles for the enter animation */
    
    .fade.ng-enter {
      transition: 0.5s linear all;
      opacity: 0;
    }
    
    
    /* The finishing CSS styles for the enter animation */
    
    .fade.ng-enter.ng-enter-active {
      opacity: 1;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-animate.js"></script>
    
    <div ng-app="myApp">
      <table ng-controller="myController">
        <tr class="heading">
          <td ng-click="toggle(0)">
            Heading
          </td>
        </tr>
        <tr ng-if="show[0]" class="fade">
          <td class="content">
            Content
          </td>
        </tr>
        <tr class="heading">
          <td ng-click="toggle(1)">
            Heading
          </td>
        </tr>
        <tr ng-if="show[1]" class="fade">
          <td class="content">
            Content
          </td>
        </tr>
      </table>
    </div>