我有2個陣列,一個是的newval,另一個是origVal定義比較2個陣列,下劃線的對象找到differnce
原稿:
[
{"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"}
]
如果我更改新的評分之一,我如何檢測該更改並檢索更改的對象?
一次只會有一個變化,但我認爲不重要。
FYI:這些陣列正在從一個Anjularjs watchcollection
$scope.$watchCollection('items', function (new, old) {
}, true);
生產謝謝 斯蒂芬
是那些陣列(即''===身份)在同一個對象還是僅僅是相似的外觀? – Bergi
你需要什麼結果?數組中已更改對象的索引,新更改對象,舊更改對象,評級? – Bergi
我更喜歡改變的對象ie {「ListingId」:1762276,「Rating」:2,「ListPrice」:7411828,「PropertyType」:「Residential」} –