gpt4 book ai didi

javascript - 如何从angularjs中的json获取特定的唯一值

转载 作者:行者123 更新时间:2023-11-30 12:13:28 26 4
gpt4 key购买 nike

我有这样的 json..

{
"Project_details": [
{
"Project_ID": "1245353445",
"Name": "Test1",
"Releases": [
{
"sid_ratio": "5.0",
"release_version": "13.2",
"pre_delivery": {
"total": "13",
"blocker": "2",
"critical": "2",
"major": "4",
"normal": "6",
"minor": "1"
},
"post_delivery": {
"total": "3",
"blocker": "2",
"critical": "0",
"major": "1",
"normal": "1",
"minor": "1"
}
},
{
"sid_ratio": "15.0",
"release_version": "14.1",
"pre_delivery": {
"total": "13",
"blocker": "3",
"critical": "2",
"major": "4",
"normal": "6",
"minor": "1"
},
"post_delivery": {
"total": "3",
"blocker": "3",
"critical": "0",
"major": "1",
"normal": "1",
"minor": "1"
}
},
{
"sid_ratio": "15.0",
"release_version": "14.2",
"pre_delivery": {
"total": "13",
"blocker": "0",
"critical": "2",
"major": "4",
"normal": "6",
"minor": "1"
},
"post_delivery": {
"total": "3",
"blocker": "0",
"critical": "0",
"major": "1",
"normal": "1",
"minor": "1"
}
}
]
}
]
}

我想在一个数组中获得唯一的 release_version..

我需要另一个数组中的键“项目 ID”和“名称”..

如何使用 angularjs 实现这一点?我想在 Controller 中获取这些数据并将这些数组分配给 $scope..

最佳答案

我知道这个问题被接受了。我喜欢纯 JavaScript。但是我无法阻止自己使用 LoDash 提供一个优雅的解决方案。

据我正确理解,您需要两个不同的数组。

提取数组中的release_version

_.pluck(data['Project_details'][0]['Releases'], 'release_version');
// ["13.2", "14.1", "14.2"]

提取Project_IdName

_.pick(data['Project_details'][0], ['Project_ID', 'Name'])
// Object {Project_ID: "1245353445", Name: "Test1"}

索引0使用是因为您的 Project_details 数组中只有一行。

关于javascript - 如何从angularjs中的json获取特定的唯一值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33094571/

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