gpt4 book ai didi

javascript - 如何使用 Angular 获取对象内属性的长度

转载 作者:行者123 更新时间:2023-11-28 19:05:14 25 4
gpt4 key购买 nike

我有一个名为programs的json对象。在这个对象中,我有一个键/值数组。我需要计算有多少对象具有“status”的键/值:“Review”。所以这里我们有 4 个对象,其中两个具有“状态”:“审核”。我需要像这样返回这个计数 (2)

{
"id": 3,
"organizationName": "Watertown School",
"programs": [
{
"id": 72,
"programId": 456456,
"programName": "name 1",
"programType": "Phd",
"applicationType": "Domestic",
"concentration": "Medicine",
"formId": 0,
"isReviewed": true,
"status": "Review"
},
{
"id": 73,
"programId": 4564561,
"programName": "name 2",
"programType": "Phd",
"applicationType": "Domestic",
"concentration": "Medicine",
"formId": 0,
"isReviewed": true,
"status": "Draft"
},
{
"id": 74,
"programId": 10343431,
"programName": "name 3",
"programType": "Phd",
"applicationType": "Domestic",
"concentration": "Medicine",
"formId": 0,
"isReviewed": true,
"status": "Review"
},
{
"id": 75,
"programId": 10031,
"programName": "namw 4",
"programType": "Phd",
"applicationType": "Domestic",
"concentration": "Medicine",
"formId": 0,
"isReviewed": true,
"status": "Draft"
},
]
}

最佳答案

取决于你在哪里需要这个?如果它在 dom 中,你可以这样做:

{{ (myObject.programs | filter:{ status: 'Review' }).length }}

这是一个 jsFiddle 显示它:http://jsfiddle.net/2jx5oL78/

关于javascript - 如何使用 Angular 获取对象内属性的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31808992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com