一、JS
1 ngApp.filter('unique', function () { 2 return function (collection, keyname) { 3 var output = [], 4 keys = []; 5 6 angular.forEach(collection, function (item) { 7 var key = item[keyname]; 8 if (keys.indexOf(key) === -1) { 9 keys.push(key); 10 output.push(item); 11 } 12 }); 13 14 return output; 15 }; 16 });
二、Html
1 <div ng-repeat="item in items | unique: 'id'"></div>