AngularJs 使用ng-repeat 时,去除重复项
2015-12-31 15:42 张小驴同学 阅读(5472) 评论(0) 编辑 收藏 举报app.filter('unique', function() { return function(collection, keyname) { var output = [], keys = []; angular.forEach(collection, function(item) { var key = item[keyname]; if(keys.indexOf(key) === -1) { keys.push(key); output.push(item); } }); return output; }; });
<div ng-repeat="item in items | unique: 'id'"></div>