请帮我编写一个jquery,在输入json下面的属性 DisplayInPPE = true 上的json文件下面进行过滤,
以下是我的输入文件和预期的输出文件
输入Json
[
{
"CategoryName":"Application Group",
"CategoryServices":[
{
"ServiceOid":"8bc2f18c-2a9a-4286-a8bc-619384c4f8c2343",
"ServiceName":"MFA",
"CloudType":[
],
"CloudTypesCount":0
},
{
"ServiceOid":"2aa3da21-9d9e-423c-86e8-7123a8f5140c332",
"ServiceName":"Azure Privileged Identity Management",
"CloudType":[
],
"CloudTypesCount":0
},
{
"ServiceOid":"f5661f9f-65cf-4349-bfe1-e2b6605ab5a3",
"ServiceName":"IDML",
"CloudType":[
{
"Id":15,
"ServiceOid":"f5661f9fj-65cf-4349-bfe1-e2b6605ab5a3s212",
"RequiresPPT":true,
"DisplayInPPE":false,
"DisplayInPROD":true
},
{
"Id":16,
"ServiceOid":"f5661f9fj-65cf-4349-bfe1-e2b6605ab5a3",
"RequiresPPT":false,
"DisplayInPPE":true,
"DisplayInPROD":false
},
{
"Id":17,
"ServiceOid":"f5661f9fj-65cf-4349-bfe1-e2b6605ab5a3444",
"RequiresPPT":true,
"DisplayInPPE":false,
"DisplayInPROD":true
}
],
"CloudTypesCount":3
}
]
}]
OutPut Json
[
{
"CategoryName":"Application Group",
"CategoryServices":[
{
"ServiceOid":"f5661f9f-65cf-4349-bfe1-e2b6605ab5a3",
"ServiceName":"IDML",
"CloudType":[
{
"Id":16,
"ServiceOid":"f5661f9f-65cf-4349-bfe1-e2b6605ab5a3",
"RequiresPPT":false,
"DisplayInPPE":true,
"DisplayInPROD":false
}
],
"CloudTypesCount":3
}
]
}]
非常感谢您的帮助。
编辑1:
好的,我自己设法解决了这个问题。如果任何人想在功能中引用
,则发布代码filteredres=jQuery.grep(data, function (element, index) {
element.CategoryServices= jQuery.grep(element.CategoryServices, function (element2, index2) {
if(element2.CloudTypesCount>0)
{
element2.CloudType= jQuery.grep(element2.CloudType, function (element3, index3) {
return element3.DisplayInPPE==true;
});
return (element2.CloudType.length!=0);
}
});
return (element.CategoryServices.length != 0);
});