【发布时间】:2020-11-13 01:44:35
【问题描述】:
我有 2 个数组,一个是 newVal,另一个是 origVal define
原件:
[
{"ListingId":1762276,"Rating":3,"ListPrice":7411828,"PropertyType":"Residential"},
{"ListingId":1826692,"Rating":3,"ListPrice":650000,"PropertyType":"Residential"},
{"ListingId":1833283,"Rating":4,"ListPrice":950000,"PropertyType":"Residential"},
{"ListingId":1832134,"Rating":3,"ListPrice":850000,"PropertyType":"Residential"},
{"ListingId":1829932,"Rating":4,"ListPrice":750000,"PropertyType":"Residential"},
{"ListingId":1827548,"Rating":5,"ListPrice":650000,"PropertyType":"Residential"}
]
新:
[
{"ListingId":1762276,"Rating":2,"ListPrice":7411828,"PropertyType":"Residential"},
{"ListingId":1826692,"Rating":3,"ListPrice":650000,"PropertyType":"Residential"},
{"ListingId":1833283,"Rating":4,"ListPrice":950000,"PropertyType":"Residential"},
{"ListingId":1832134,"Rating":3,"ListPrice":850000,"PropertyType":"Residential"},
{"ListingId":1829932,"Rating":4,"ListPrice":750000,"PropertyType":"Residential"},
{"ListingId":1827548,"Rating":5,"ListPrice":650000,"PropertyType":"Residential"}
]
如果我更改新的评级之一,我如何检测到该更改并检索更改的对象?
一次只会有一个变化,虽然我认为这并不重要。
仅供参考:这些数组是由 Anjularjs watchcollection 生成的
$scope.$watchCollection('items', function (new, old) {
}, true);
谢谢, 斯蒂芬
【问题讨论】:
-
这些是数组中的相同对象(即
===身份)还是只是看起来相似? -
你需要什么结果?更改对象在数组中的索引,新更改对象,旧更改对象,评分?
-
我更喜欢更改后的对象,即 {"ListingId":1762276,"Rating":2,"ListPrice":7411828,"PropertyType":"Residential"}