0
我有以下的JSON對象:Angularjs嵌套MD-虛擬重複
[
{
"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"
}
]
}
]
我想用md-virtual-repeat
指令來顯示此數據。當我使用這個指令時,一級中繼器工作。 但是,當我嘗試使用相同的指令呈現內部數據 - 它不會按預期工作。如何使用md-virtual-repeat
爲嵌套中繼器(我想擺脫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);
}
});
.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;
}
<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-subheader flex>Item</md-subheader>
</md-list-item>
<md-list-item ng-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-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>
這是一個完成此操作的codepen:https://codepen.io/semihgk/pen/Pzrwkj。除了你的數據結構之外,你不會得到任何幫助。 –
不,我也想在內部數據中使用虛擬中繼器。 – Aswathy
@ShriyaR你是否嘗試過從我的答案中使用標記? –