我有一个复杂的JSON对象,我想进行以下比较:
$scope.new = [
{
"name": "Node-1",
"isParent": true,
"text" : [
{
"str" : "This is my first Node-1 string",
"parent":[]
},
{
"str" : "This is my second Node-1 string",
"parent":[]
}],
"nodes": [
{
"name": "Node-1-1",
"isParent": false,
"text" : [
{
"str" : "This is my first Node-1-1 string",
"parent":[]
},
{
"str" : "This is my second Node-1-1 string",
"parent":[]
}],
"nodes": [
{
"name": "Node-1-1-1",
"isParent": false,
"text" : [
{
"str" : "This is my first Node-1-1-1 string",
"parent":[]
},
{
"str" : "This is my second Node-1-1-1 string",
"parent":[]
}],
"nodes": []
}
]
}
]
}
]
但是,当我进行比较时,我想要忽略一个属性,但是由于我正在使用Angular.js,我没有看到任何选项可以在比较两个对象时省略该属性。
console.log(angular.equals($scope.new,$scope.copy));
在研究过程中,我找到了以下使用lodash的答案,它具有emit选项,但问题是我猜测omit会创建一个副本,在lodash的情况下可能会导致性能下降。
因此,现在我想将对象转换为字符串,然后进行比较,我想这样会更快,但问题是在字符串比较时如何省略该属性?
像这样:
var str1 = JSON.stringify(JSON.stringify($scope.new));
var str2 = JSON.stringify(JSON.stringify($scope.copy));
console.log(str1==str2);
注意:我想在比较两个对象时忽略isParent
属性。
最好的方法是什么来比较两个对象?
isParent
属性,还是所有嵌套对象的isParent
属性都要忽略? - Guillermo Moratorio