angularjs怎么自定义过滤器去掉重复项 30
比如$scope.items=[{name:"name1",price:1,catalog:1},{name:"name2",price:2,catalog:2},{na...
比如
$scope.items=[
{name:"name1",price:1,catalog:1},
{name:"name2",price:2,catalog:2},
{name:"name3",price:3,catalog:3},
{name:"name4",price:4,catalog:1},
{name:"name5",price:5,catalog:2},
{name:"name6",price:6,catalog:3}
];
我想有个导航显示类别123 展开
$scope.items=[
{name:"name1",price:1,catalog:1},
{name:"name2",price:2,catalog:2},
{name:"name3",price:3,catalog:3},
{name:"name4",price:4,catalog:1},
{name:"name5",price:5,catalog:2},
{name:"name6",price:6,catalog:3}
];
我想有个导航显示类别123 展开
2个回答
展开全部
这个只能自己写过滤方法了
function unique(arr, key){
var tempArr = arr;
for(var i = 0;i < tempArr.length;i++){
for(var j = 0;j< tempArr.length;j++){
if(tempArr[i][key] == tempArr[j][key]){
arr.splice(j,1);
}
}
}
return arr;
}
unique($scope.items,'name')
function unique(arr, key){
var tempArr = arr;
for(var i = 0;i < tempArr.length;i++){
for(var j = 0;j< tempArr.length;j++){
if(tempArr[i][key] == tempArr[j][key]){
arr.splice(j,1);
}
}
}
return arr;
}
unique($scope.items,'name')
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询