这是Compare two arrays and update with the new values by keeping the existing objects using javascript的后续问题,@Siderite Zackwehdex已经回答
请检查一下plunker我在changedArray1.Is中找到了已删除的对象。有任何选项可以修复此问题。它可以正常用于其他更改,例如添加,更新但不能删除。
我尝试实现的一个功能是添加一个额外的对象,即。"removedIds":[23] ,
,将已删除的id作为数组保存在每个对象级别中,并在评估过程中识别它们。但是没有找到合适的灵魂
示例数据:
var parentArray1=[
{
"id": 1,
"name": "test",
"context": [
{
"operationalContextId": 1.1,
"valueChainEntityDetails": [
{
"valuChainEntityId": 3,
"name": "test",
"context": [
{
"id": 3.1,
"name": "test 3.1",
"activityDetails": [
{
"activityId": 22,
"name": "test 3.1"
},
{ //trying to remove activity id 23
"activityId": 23,
"name": "changed test 23"
}
]
}
]
}
]
}
]
}
]
var changedArray1=[
{
"id": 1,
"name": "test2",
"context": [
{
"operationalContextId": 1.1,
"valueChainEntityDetails": [
{
"valuChainEntityId": 3,
"name": "changed test3",
"context": [
{
"id": 3.1,
"name": "test 3.1",
"removedIds":[23] ,
"activityDetails": [ //activity id 23 is removed in this JSON but reflecting in parentArray1
{
"activityId": 22,
"name": "changed test 3.1"
}
]
}
]
}
]
}
]
}
]