您可以使用angular.filter模块的groupBy过滤器。
因此您可以执行以下 *** 作:
用法:
collection | groupBy:property
使用带点标记的嵌套属性:
property.nested_property
JS:
$scope.players = [ {name: 'Gene', team: 'alpha'}, {name: 'George', team: 'beta'}, {name: 'Steve', team: 'gamma'}, {name: 'Paula', team: 'beta'}, {name: 'Scruath', team: 'gamma'}];
HTML:
<ul ng-repeat="(key, value) in players | groupBy: 'team'"> Group name: {{ key }} <li ng-repeat="player in value"> player: {{ player.name }} </li></ul>
结果:
组名:alpha
播放器:Gene
组名:beta
播放器:George
播放器:Paula
组名:gamma
播放器:Steve
*播放器:Scruath
更新: jsbin
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)