[html] view plain copy print?在CODE上查看代码片派生到我的代码片
<div ng-app="myApp" ng-controller="myCtrl">
<p ng-repeat="x in items | unique:'id'">
{{x.id}}---{{x.name}}
</p>
</div>
<script>
//AngularJs 自定义过滤器
//1.使用过滤器,去除重复
angular.module('common', []).filter('unique', function () {
return function (collection, keyname) {
console.info(collection);
console.info(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;
}
});
var app = angular.module('myApp', ['common']);
app.controller('myCtrl', function ($scope) {
//$scope.items = [1, 2, 3,2];
//当前unique 的过滤只针对,对象数组过滤
$scope.items = [
{ id: 1, name: 'zhangsan' },
{ id: 2, name: 'lisi' },
{ id: 1, name: 'zhangsan' },
];
});
</script>

  

最新文章

  1. react开发环境搭建
  2. BIOS开启虚拟化
  3. CSS抗锯齿 font-smoothing 属性介绍
  4. Spring MVC Cookie example
  5. Cocos2d-x 多分辨率适配完全解析
  6. Spring MVC 使用介绍(七)—— 注解式控制器(三):生产者与消费者模型
  7. traditional ajax提交数据有列表的时候需要添加
  8. canvas一些属性
  9. python json读取与解析
  10. 535种使用JavaScript重新加载页面的方法
  11. ansible详解
  12. (4.29)sql server中有关于GO的坑
  13. STL之List容器
  14. 20155208实验三 敏捷开发与XP实践
  15. Go Example--切片
  16. camtasis studio 未能创建视频内存资源。
  17. mysql 授权命令
  18. Linux tar包相关命令
  19. hashcode()和equals()方法
  20. 在matlab中clear,clc,clf,hold作用介绍

热门文章

  1. OPENFIRE 接收数据流程图
  2. codevs 1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛
  3. fun下载内容批量收集
  4. UVA 1412 Fund Management (预处理+状压dp)
  5. ftl-server静态资源服务器
  6. 数据库_6_SQL基本操作——库操作
  7. 二. python函数与模块
  8. 初涉平衡树「treap」
  9. mysqldump导出备份数据库报Table ‘performance_schema.session_variables‘ doesn‘t exist
  10. cache支持single/increment/increment4三种方式传输