我有一个编辑表单。
在哪里获取JSON
$scope.allDeviceData= [];
,角度复制为
$scope.allDeviceDataCopy= [];
allDeviceData
是:allDeviceData = [{
"id": "31",
"log_time": "7",
"record_mode": "0",
"upload_interval": "6",
"sampling_time": "3",
"log_method": "3",
"ntp_setting": "0",
"header1": "MyCloud0",
"footer": "MyCloud",
"autodownload": "0",
"autoupdatetime": "0",
"downloaded_time": null,
"unit_id": "144",
"userid": "19",
"unit_name": "living window",
"mac_id": "C20BFCFF9C44",
"group_name": "testing",
"mdlno": "Mmag",
"battery_val": "0",
"battery": {
"id": "2604709",
"battery_val": "3.3",
"network_val": "-62",
"updatetime": "2018-09-14 00:43:35 ",
"unit_id": "144"
},
"channelinfo": [{
"id": "5462236",
"chkey": "ch1",
"chvalue": "0",
"updatetime": "2018-09-14 00:43:35 ",
"unit_id": "144"
}],
"channels": [{
"id": "59",
"chkey": "ch1",
"unit_id": "144",
"input_type": "Magnetic",
"unit": "unit",
"decimal_value": "0",
"offset_value": "0",
"gain_value": "0",
"range_low": "0",
"range_high": "0",
"high_name": "opened",
"low_name": "0",
"Condition_high": "0",
"Condition_low": "0",
"Threshold_high": "4",
"Threshold_low": "0",
"reset_low": "0",
"reset_high": "0",
"activate_high": "0",
"activate_low": "0",
"notify_high": "1",
"notify_low": "0",
"Judgtime_high": "4",
"judgetime_low": "0",
"tempchvalue": "0",
"chtempvalue1": "0"
}]
}]
我想比较allDeviceData
和allDeviceDataCopy
并仅发送更改的字段并删除其他字段。
我该怎么做?
答案 0 :(得分:1)
您可以使用angular.equals(https://docs.angularjs.org/api/ng/function/angular.equals)来获取更改后的数据是否脏。 如果不干净,则可以迭代并比较值并获取更改后的值。