0
我正在使用下劃線js的_.isFilter方法。如果我想檢查2個JSON是否相同,它會很好地工作。但我正面臨一個小問題。在一個JS中,我有$$ hashKey作爲屬性,而在其他情況下它不存在。我怎樣才能比較2個JSON的所有屬性,除了一個就是$$ hashKey。如何比較2個JSON的所有屬性,除了一個,使用UnderscoreJs?
$rootScope.jsonOfHRA = $scope.setFileNameAndOtherProperties($rootScope.jsonOfHRA);
globalJsonHRA = JSON.parse(JSON.stringify($rootScope.jsonOfHRA));
//This is how I make a deep copy of JSON
JSONOFHRA=
{
"toShowVerified": 0,
"sec10_decl_id": 390,
"toShowEdit": 0,
"toShowlineItemEditable": true,
"edit": false,
"sec10_decl_act_val": 0,
"sec10_decl_other_text1": "asdsa",
"sec10_decl_other_text2": "3434",
"sec10_decl_other_text3": "adasda",
"sec10_decl_decl_from_dt": "01/05/2014",
"sec10_decl_status": 0,
"sec10_decl_yr_end": "2015-03-31",
"sec10_decl_yr_id": 2014,
"listOfAttachments": [],
"nameOfPayheadToShow": "HRA",
"sec10_decl_proof": 0,
"sec10_decl_ver_val": 0,
"sec10_decl_yr_st": "2014-04-01",
"sec10_decl_cust_id": 315,
"add": false,
"sec10_decl_curr_id": 0,
"sec10_decl_mod_on": "2014-10-28 12:46:14.0",
"sec10_decl_add_on": "2014-10-28 12:38:49.0",
"sec10_decl_decl_to_dt": "30/06/2014",
"sec10_decl_user_id": 32967,
"sec10_decl_active": 0,
"sec10_decl_decl_val": 1234,
"sec10_decl_head_id": 3,
"sec10_decl_decl_text": "Delhi",
"$$hashKey": "19I"
}
GLOBALJSON =
{
"toShowVerified": 0,
"sec10_decl_id": 390,
"toShowEdit": 0,
"toShowlineItemEditable": true,
"edit": false,
"sec10_decl_act_val": 0,
"sec10_decl_other_text1": "asdsa",
"sec10_decl_other_text2": "3434",
"sec10_decl_other_text3": "adasda",
"sec10_decl_decl_from_dt": "01/05/2014",
"sec10_decl_status": 0,
"sec10_decl_yr_end": "2015-03-31",
"sec10_decl_yr_id": 2014,
"listOfAttachments": [],
"nameOfPayheadToShow": "HRA",
"sec10_decl_proof": 0,
"sec10_decl_ver_val": 0,
"sec10_decl_yr_st": "2014-04-01",
"sec10_decl_cust_id": 315,
"add": false,
"sec10_decl_curr_id": 0,
"sec10_decl_mod_on": "2014-10-28 12:46:14.0",
"sec10_decl_add_on": "2014-10-28 12:38:49.0",
"sec10_decl_decl_to_dt": "30/06/2014",
"sec10_decl_user_id": 32967,
"sec10_decl_active": 0,
"sec10_decl_decl_val": 1234,
"sec10_decl_head_id": 3,
"sec10_decl_decl_text": "Delhi"
}
//This is how I am comparing
if(_.isEqual(modifiedJson[i], GlobalUnmodifiedJson[j])){
var idOfUnmodifiedLineItem = modifiedJson[i]["sec10_decl_id"];
alert("Coming here in realm of unmodified of modifed");
modifiedJson = _.filter(modifiedJson, function(item) {
return item.id !== idOfUnmodifiedLineItem;
});