gpt4 book ai didi

javascript - 比较 AngularJS 中的 Angular 副本和更改的数据并仅发送更改的项目

转载 作者:行者123 更新时间:2023-12-03 01:04:25 25 4
gpt4 key购买 nike

我有一个编辑表单。
我在哪里获得 JSON 为

$scope.allDeviceData= [];   

和 Angular 复制为

$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"
}]
}]

我想比较 allDeviceDataallDeviceDataCopy 并仅发送更改的字段并删除其他字段。

我该怎么做?

最佳答案

可以使用 angular.equals( https://docs.angularjs.org/api/ng/function/angular.equals ) 来获取更改后的数据是否为脏数据。如果脏,那么您可以迭代并比较这些值并获取更改后的值。

关于javascript - 比较 AngularJS 中的 Angular 副本和更改的数据并仅发送更改的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52473173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com