【发布时间】:2016-03-07 12:14:47
【问题描述】:
我有一个 Json 对象。
[{
"id":"1",
"username": "vishnu",
"FromDate": "Wed Mar 02 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "createwhimsy",
"task": "fixing bugs",
"time": "1"
}, {
"id":"2",
"username": "seenu",
"FromDate": "Wed Mar 02 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "createwhimsy",
"task": "working on ui",
"time": "2"
}, {
"id":"3",
"username": "sam",
"FromDate": "Wed Mar 02 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "bigiron",
"task": "working on api",
"time": "5"
},
{
"id":"4",
"username": "vishnu",
"FromDate": "Wed Mar 03 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "timetracker",
"task": "ui designing",
"time": "1"
},{
"id":"5",
"username": "arun",
"FromDate": "Wed Jan 02 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "createwhimsy",
"task": "fixing bugs",
"time": "1"
}, {
"id":"6",
"username": "seenu",
"FromDate": "Wed Mar 01 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "createwhimsy",
"task": "working on ui",
"time": "2"
}, {
"id":"7",
"username": "sam",
"FromDate": "Wed Mar 03 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "createwhimsy",
"task": "working on api",
"time": "6"
},
{
"id":"8",
"username": "vishnu",
"FromDate": "Wed Mar 03 2016 10:56:45 GMT+0530 (India Standard Time)",
"selectedProject": "timetracker",
"task": "ui designing",
"time": "4"
}]
我想制作一个自定义过滤器来过滤特定用户(根据用户名),并从过滤后的数据中获取长度。 例如,用户名:Vishnu,我想过滤并检查用户名 Vishnu 有多少对象。像这样,我想为所有用户获取。
我创建了一个自定义过滤器,例如(键入的代码,不正确),
app.filter('myfilter',function(){
return function(mydata){
var filterd data=[];
angular.foreach(mydata,function(s){
if(s.name==$scope.model)
{
filtereddata.push(s)
}
})
return filtereddata;
}
});
现在我该怎么办?
【问题讨论】:
-
您的数据有
username,但您的检查是基于name...
标签: javascript angularjs ionic-framework