html - ngRepeat by grouping the same property w/o another library -


i have series of objects properties, of them have same value in property called "region". group these objects region property (i.e. if in same region, group them together), , display many regions there these objects in different tables. cannot figure out how in ng-repeat. here example of list of objects:

[{"name": 000, "region": cus, "weight": 1}, {"name": 001, "region": cus, "weight": 2}, {"name": 003, "region": wus, "weight": 2}] 

the goal ng-repeat on table tag tables produced regions "cus" , "wus," 2 tables 000 , 001 in cus table , 002 in wus table.

for reasons not explain here, prefer not use library angularjs achieve desired result. many of suggested groupby property can added there way native angular code?

thanks help.

angular.module('app',['angular.filter'])    function main($scope) {  	var = [{"name": 000, "region": 'cus', "weight": 1}, {"name": 001, "region": 'cus', "weight": 2}, {"name": 003, "region": 'wus', "weight": 2}]      $scope.a = a;  }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  <script src="//cdnjs.cloudflare.com/ajax/libs/angular-filter/0.4.7/angular-filter.js"></script>  <body ng-app="app" ng-controller="main">  	<div ng-repeat="(key, value) in (a | groupby: 'region')">  		group name: {{ key }}  		<table>  			<tr>  				<th>name</td>  				<th>weight</td>  			</tr>  			<tr ng-repeat="item in value">  				<td>{{item.name}}</td>  				<td>{{item.weight}}</td>  			</tr>  		</table>  	</div>  </body>

edit : used filter | groupby instead of lodash.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -