2 つのオブジェクト間で変更 (差分) されたプロパティを返すにはどうすればよいですか?
私のコードでは、products_diy
データを格納するグローバル変数を設定しました。ページのフィルターの値を変更すると、products_diy
それに応じて値が変更されます。の元の値と現在の値の間で変更 (差分) された値を取得したいと思いますproducts_diy
。
この比較関数を書くのは難しすぎます。誰かが助けますか?
function obj_diff(o2, o1) {
var obj = {};
for (var i in o1) {
var item_type = typeof o2[i];
if (item_type != 'undefined') {
//...
}
}
return obj;
}
var products_diy1 = {
'zone': [1, 2],
'category': {
'c0': '1'
},
'fitler': {
'price': {
'switcher': 'true',
'price_start': '30',
'price_end': '50'
}
}
}
var products_diy2 = {
'zone': [1, 2, 3],
'category': {
'c0': '1'
},
'fitler': {
'price': {
'switcher': 'true',
'price_start': '30',
'price_end': '80'
}
}
}
/* -------
compare 2 objects
if the item in o2 is not the same with the o1,
join item to returned obj
obj_diff = {
'zone': [1, 2, 3],
'fitler': {
'price': {
'switcher': 'true',
'price_start': '30',
'price_end': '80'
}
}
}
------- */