我有这个示例json数据:
{
"sessionsData" :[{
"isActive": true,
"isInactive": false,
"isScheduled": false,
"isExpired": false,
"candidateName":"Payal Singh",
"email": "ggera@sapient.com"
},
{
"isActive": false,
"isInactive": true,
"isScheduled": false,
"isExpired": false,
"candidateName":"Shyam Singh",
"email": "ggera@sapient.com"
},
{
"isActive": false,
"isInactive": false,
"isScheduled": true,
"isExpired": false,
"candidateName":"Payal Singh",
"email": "ggera@sapient.com"
},
{
"isActive": false,
"isInactive": false,
"isScheduled": false,
"isExpired": true,
"candidateName":"Payal Singh",
"email": "ggera@sapient.com"
}]
}
现在我只想通过使用angular来计算将“isActive”属性设置为true的条目。 有人有什么建议吗?
答案 0 :(得分:1)
arr.sessionsData.filter(function(obj,key){
return obj.isActive==true
})
OR:
ECMA6:
var arrFiltered = arr.sessionsData.filter((obj,key)=>
obj.isActive==true
)
答案 1 :(得分:0)
https://docs.angularjs.org/api/ng/filter/filter。按照这个链接,它非常详细。我这样做了:
$scope.activeEntries = $filter('filter')($scope.session.sessionsData, {isActive: true});
其中$ scope.session.sessionsData是我在其中检索json数据的数组。