【问题标题】:how to toggle rows in angular to expand or collapse row as in accordian?如何像手风琴一样以角度切换行以展开或折叠行?
【发布时间】:2015-07-02 11:23:02
【问题描述】:

你能告诉我如何在 angular 中切换行。换句话说,我制作了一个简单的 angular 可折叠行示例项目,当用户单击与 Accordion 中相同的行时,它会展开。所以我的问题是当我点击第一行时它打开或展开第三行为什么?只有第一行会扩展..我们可以添加一些衬里过渡,它看起来像向上滑动和向下滑动的方式。

点击第一行它展开第三行为什么?

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

    <title>Ionic Swipe Down</title>

    <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
    <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>

    <script src="http://code.ionicframework.com/contrib/ionic-contrib-swipecards/ionic.swipecards.js?v=5"></script>
    <script src="script.js"></script>

</head>
<style>
    .bg {
        background: lightgray;
        position: relative;
    }
    .ptag {
        position: absolute;
        top:0;
        left:0;
        width: 7%;
        border: 1px solid red;
        height: 100%;
        background: lightblue;
        color: white;
    }
    .circle{
        width: 50px;
        height: 50px;
        float: right;
        border-radius: 100%;
        background: green;
        margin-top: -7%;
        line-height: 50px;
        text-align: center;
        color:black!important;
    }
</style>
<body ng-app="app">
<div ng-controller="apptes">
<div class="list card">

    <div class="item item-avatar bg"  ng-click="clickrow()" ng-repeat="n in obj">
       <p class="ptag">P</p>
        <h2>{{n.number}}</h2>
        <p>{{n.name}}</p>
        <p class="circle">650</p>
    </div>
<div ng-show="toogle_item">
    <div class="item item-body" >

        <p>
            This is a "Facebook" styled Card. The header is created from a Thumbnail List item,
            the content is from a card-body consisting of an image and paragraph text. The footer
            consists of tabs, icons aligned left, within the card-footer.
        </p>
        <p>
            <a href="#" class="subdued">1 Like</a>
            <a href="#" class="subdued">5 Comments</a>
        </p>
    </div>

    <div class="item tabs tabs-secondary tabs-icon-left">
        <a class="tab-item" href="#">
            <i class="icon ion-thumbsup"></i>
            Like
        </a>
        <a class="tab-item" href="#">
            <i class="icon ion-chatbox"></i>
            Comment
        </a>
        <a class="tab-item" href="#">
            <i class="icon ion-share"></i>
            Share
        </a>
    </div>
</div>
</div>
</div>

</body>
</html>

我们可以添加上滑并以慢动作滑动吗?

【问题讨论】:

    标签: angularjs angularjs-directive angularjs-scope angularjs-ng-repeat ionic-framework


    【解决方案1】:

    这是你想要的,或者至少是一个起始布局:

    HTML:

    <html ng-app="ionicApp">
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
        <title>Ionic Accordion</title>
    
        <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
        <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
    
      </head>
    
      <body ng-controller="MyCtrl">
    
        <ion-header-bar class="bar-positive">
          <h1 class="title">Accordion List</h1>
        </ion-header-bar>
    
        <ion-content>
    
          <ion-list>
            <div ng-repeat="group in groups">
              <ion-item class="item-stable"
                        ng-click="toggleGroup(group)"
                        ng-class="{active: isGroupShown(group)}">
                  <i class="icon" ng-class="isGroupShown(group) ? 'ion-minus' : 'ion-plus'"></i>
                &nbsp;
                Group {{group.name}}
              </ion-item>
              <ion-item class="item-accordion"
                        ng-repeat="item in group.items"
                        ng-show="isGroupShown(group)">
                {{item}}
              </ion-item>
            </div>
          </ion-list>
    
        </ion-content>
    
      </body>
    </html>
    

    JS:

    angular.module('ionicApp', ['ionic'])
    
    .controller('MyCtrl', function($scope) {
      $scope.groups = [];
      for (var i=0; i<10; i++) {
        $scope.groups[i] = {
          name: i,
          items: []
        };
        for (var j=0; j<3; j++) {
          $scope.groups[i].items.push(i + '-' + j);
        }
      }
    
      /*
       * if given group is the selected group, deselect it
       * else, select the given group
       */
      $scope.toggleGroup = function(group) {
        if ($scope.isGroupShown(group)) {
          $scope.shownGroup = null;
        } else {
          $scope.shownGroup = group;
        }
      };
      $scope.isGroupShown = function(group) {
        return $scope.shownGroup === group;
      };
    
    });
    

    CSS:

    body {
      cursor: url('http://ionicframework.com/img/finger.png'), auto;
    }
    
    /*
     * http://docs.angularjs.org/api/ng/directive/ngShow#usage_animations
     */
    .list .item.item-accordion {
      line-height: 38px;
      padding-top: 0;
      padding-bottom: 0;
      transition: 0.09s all linear;
    }
    .list .item.item-accordion.ng-hide {
      line-height: 0px;
    }
    .list .item.item-accordion.ng-hide-add,
    .list .item.item-accordion.ng-hide-remove {
      display: block !important;
    }
    

    代码笔:http://codepen.io/ionic/pen/uJkCz

    【讨论】:

      猜你喜欢
      • 2012-09-23
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      • 2014-01-25
      • 2011-06-19
      • 2016-10-29
      • 1970-01-01
      相关资源
      最近更新 更多