enter image description here在按组名对 json 进行排序时,如何将IsMerged Json属性设置为true?
SampleJson:
[{"SessionId":"s1",
"SessionName":"Session Name 1",
"StartDateTime":"2019-05-16T04:00:00",
"Groups":[
{"GroupID":"g1",
"GroupName":"Group Name1",
"HideChildren":false,
"IsMerged":false
},
{"GroupId":"g2",
"GroupName":"Group Name2",
"HideChildren":false,
"IsMerged":false
}
//...
}]
像上面一样,有不同的会话和组(嵌套JSON)。 我可以使用$ filter
进行排序答案 0 :(得分:0)
Let groupNameSelected ='Group Name2'
let q = p[0]['Groups'];
q.map((obj)=>{
return groupNameSelected === obj.GroupName ? {...obj, IsMerged:true } : obj;
});
基于所选的组名,您将在Groups
上运行map,然后将IsMerged
的值设置为true。
Group Name2
的最终输出为:
[ { GroupID: 'g1',
GroupName: 'Group Name1',
HideChildren: false,
IsMerged: false },
{ GroupId: 'g2',
GroupName: 'Group Name2',
HideChildren: false,
IsMerged: true }
//...
]