angular中ng-repeat去重
2024-09-04 09:02:45
[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>
最新文章
- react开发环境搭建
- BIOS开启虚拟化
- CSS抗锯齿 font-smoothing 属性介绍
- Spring MVC Cookie example
- Cocos2d-x 多分辨率适配完全解析
- Spring MVC 使用介绍(七)—— 注解式控制器(三):生产者与消费者模型
- traditional ajax提交数据有列表的时候需要添加
- canvas一些属性
- python json读取与解析
- 535种使用JavaScript重新加载页面的方法
- ansible详解
- (4.29)sql server中有关于GO的坑
- STL之List容器
- 20155208实验三 敏捷开发与XP实践
- Go Example--切片
- camtasis studio 未能创建视频内存资源。
- mysql 授权命令
- Linux tar包相关命令
- hashcode()和equals()方法
- 在matlab中clear,clc,clf,hold作用介绍
热门文章
- OPENFIRE 接收数据流程图
- codevs 1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛
- fun下载内容批量收集
- UVA 1412 Fund Management (预处理+状压dp)
- ftl-server静态资源服务器
- 数据库_6_SQL基本操作——库操作
- 二. python函数与模块
- 初涉平衡树「treap」
- mysqldump导出备份数据库报Table ‘performance_schema.session_variables‘ doesn‘t exist
- cache支持single/increment/increment4三种方式传输