我有下面的对象数组,每个对象都有一个projects属性,该属性还具有其对象数组。
const data = [
{
"title": "Release",
"projects": [
{
"name": "Server",
"result": {
"success": 0,
"failure": 100
},
}
]
},
{
"title": "Payments",
"projects": [
{
"name": "Platform1",
"result": {
"success": 100,
"failure": 0
}
},
{
"name": "Platform2",
"result": {
"success": 50,
"failure": 50,
}
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
我想迭代它并得到如下结果。name无非是上述数据的title和 的串联name。
const result = [
{
name: 'Release-Server',
success: 0,
failure: 100,
},
{
name: 'Payments-Platform1',
success: 100, …Run Code Online (Sandbox Code Playgroud) 我发现过滤嵌套对象数组很困难。有人可以让我知道我哪里出了问题吗?
这是数据,我想过滤掉所有有风险的对象P1
{
"title": "QA",
"rows": [
{
"risk": "P1",
"Title": "Server down",
},
{
"risk": "P3",
"Title": "Permission issue",
}
]
},
{
"title": "Prod",
"rows": [
{
"risk": "P5",
"Title": "Console log errors fix",
},
{
"risk": "P1",
"Title": "Server is in hung state",
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
我想要的结果如下
[
{
"title": "QA",
"rows": [
{
"risk": "P1",
"Title": "Server down",
}
]
},
{
"title": "Prod",
"rows": [
{
"risk": "P1",
"Title": "Server is in hung …Run Code Online (Sandbox Code Playgroud)