Angularjs嵌套Md-Virtual重复

时间:2017-08-10 17:26:09

标签: angularjs angular-material

我有以下JSON对象:

var mobileMapping = googletag.sizeMapping().    
                            addSize([0, 0], [[320,50],[320,100],[320,150]]).
                            build();

我想使用md-virtual-repeat指令显示此数据。当我使用此指令时,第一级转发器工作。 但是当我尝试使用相同的指令渲染内部数据时 - 它没有按预期工作。如何使用md-virtual-repeat嵌套转发器(我希望摆脱[ { "districtId": 1, "districtAddress": "108 N MAIN ST", "offices": [ { "Id": 11, "name": "test", "City": "ATMORE" }, { "Id": 22, "name": "test", "City": "ATMORE" } ] }, { "districtId": 2, "districtAddress": "108 N MAIN ST", "offices": [ { "Id": 33, "name": "test", "City": "ATMORE" }, { "Id": 44, "name": "test", "City": "ATMORE" } ] }, { "districtId": 3, "districtAddress": "108 N MAIN ST", "offices": [ { "Id": 55, "name": "test", "City": "ATMORE" } ] } ] 元素上的ng-repeat

这是我的代码:



md-list-item

angular
  .module('MyApp',['ngMaterial'])
  .controller('AppCtrl', function($scope) {
  var self = this;
    self.items = [];
    for (var i = 0; i < 1000; i++) {
      var item = {
        nbr: i,
        items: []
      };
      for(var m = 0; m < 10; m++) {
        item.items.push({
          nbr: m,
          checked: true
        });
      }
      self.items.push(item);
    }

  });
&#13;
.virtualRepeatStoreList .vertical-container {
    height: 500px;
    width: 100%;
}

.virtualRepeatStoreList .repeated-item {
    border-bottom: 1px solid #ddd;
    box-sizing: border-box;;
    height: 40px;
    padding-top: 10px;
}
.virtualRepeatStoreList md-content {
    margin: 16px;
}


.virtualRepeatStoreList .md-virtual-repeat-container .md-virtual-repeat-offsetter div {
    padding-left: 5px;
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

您需要使用md-virtual-repeat封装每个嵌套md-virtual-repeat-container,如:

angular
  .module('MyApp',['ngMaterial'])
  .controller('AppCtrl', function($scope) {
  var self = this;
    self.items = [];
    for (var i = 0; i < 1000; i++) {
      var item = {
        nbr: i,
        items: []
      };
      for(var m = 0; m < 10; m++) {
        item.items.push({
          nbr: m,
          checked: true
        });
      }
      self.items.push(item);
    }

  });
.virtualRepeatStoreList .vertical-container {
    height: 500px;
    width: 100%;
}

.virtualRepeatStoreList .repeated-item {
    border-bottom: 1px solid #ddd;
    box-sizing: border-box;;
    height: 40px;
    padding-top: 10px;
}
.virtualRepeatStoreList md-content {
    margin: 16px;
}


.virtualRepeatStoreList .md-virtual-repeat-container .md-virtual-repeat-offsetter div {
    padding-left: 5px;
}

md-list-item.md-no-proxy.md-no-padding {
  padding: 0;
}
<link rel="stylesheet prefetch" href="https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.0/angular-material.css">
<link rel="stylesheet prefetch" href="https://material.angularjs.org/1.1.0/docs.css">

<div ng-controller="AppCtrl as ctrl"  class="content virtualRepeatStoreList" ng-app="MyApp">
  <md-virtual-repeat-container class="vertical-container" style="height:550px">
    <div md-virtual-repeat="item in ctrl.items">
    <md-card flex="">
      <md-card-title>
        <md-card-title-text>
          <span class="md-display-2">{{ item.nbr }}</span>
        </md-card-title-text>
      </md-card-title>
      <md-list style="overflow:auto;height:auto;" flex ng-cloak layout="column">
        <md-divider></md-divider>
        <md-list-item layout="row" class="noright md-no-padding">
          <md-subheader flex>Item</md-subheader>
        </md-list-item>
        <md-virtual-repeat-container class="vertical-container" style="height:125px">
          <md-list-item md-virtual-repeat="it in item.items" style="max-height:40px;overflow:hidden;" class="noright">
            <p>{{ it.nbr }}</p>
            <md-checkbox class="md-secondary" ng-model="it.checked"></md-checkbox>
          </md-list-item>
        </md-virtual-repeat-container>
      </md-list>
    </md-card>
  </div>
  </md-virtual-repeat-container>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular-aria.min.js"></script>
<script src="https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.0/angular-material.js"></script>