假设有两个数组对象,分别为
[
{
"hasChildren": false,
"name": "小苔便利店001号店",
"pid": "588",
"id": "1428553074498211840",
"label": "小苔便利店001号店",
"deptType": 2,
"leaf": true
},
{
"hasChildren": false,
"name": "小苔峰山路店",
"pid": "1872",
"id": "1436202778274959360",
"label": "小苔峰山路店",
"deptType": 2,
"leaf": true
},
{
"hasChildren": false,
"name": "库存测试门店",
"pid": "1867",
"id": "1455718406148984832",
"label": "库存测试门店",
"deptType": 2,
"leaf": true
}
]
和
[
{
"id": "1428553074498211840",
"name": "小苔便利店001号店",
"type": 1,
"discountRate": 25,
"fixedPrice": null
},
{
"id": "1436202778274959360",
"name": "小苔峰山路店",
"type": 2,
"discountRate": null,
"fixedPrice": 50
},
{
"id": "1455718406148984832",
"name": "库存测试门店",
"type": 2,
"discountRate": null,
"fixedPrice": 200
}
]
他们的id一一对应,所以认为是两组相同的数据
现在再对第一组数据操作,可能添加一条或删除一条
如果添加一条,那么第一组数据变成4条,此时要把这条数据添加到第二组中
如果删除一条,那么第一组数据变成2条,此时要在第二组中删除这条数据
无论添加还是删除,均不能影响第二组中原有的数据
这种无脑的话就循环遍历了