如何获得两个 JavaScript 对象图之间差异的列表? [英] How can I get a list of the differences between two JavaScript object graphs?

查看:22
本文介绍了如何获得两个 JavaScript 对象图之间差异的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够获得两个 JavaScript 对象图之间所有差异的列表,以及发生增量的属性名称和值.

I want to be able to get a list of all differences between two JavaScript object graphs, with the property names and values where the deltas occur.

就其价值而言,这些对象通常以 JSON 的形式从服务器检索,并且通常不超过几层深(即它可能是一个本身具有数据的对象数组,然后是具有其他数据对象的数组).

For what it is worth, these objects are usually retrieved from the server as JSON and typically are no more than a handful of layers deep (i.e. it may be an array of objects that themselves have data and then arrays with other data objects).

我不仅要查看基本属性的变化,还要查看数组成员数量的差异等.

I want to not only see the changes to basic properties, but differences in the number of members of an array, etc. etc.

如果我没有得到答案,我可能最终会自己写这篇文章,但希望有人已经完成了这项工作,或者知道有人做过这项工作.

If I don't get an answer, I will probably end up writing this myself, but hope someone has already done this work or know of someone who has.

这些对象通常在结构上非常接近,所以我们不是在谈论彼此完全不同的对象,但可能有 3 或 4 个增量.

These objects will typically be very close in structure to one another, so we are not talking about objects that are utterly different from one another, but may have 3 or 4 deltas.

推荐答案

在查看现有答案后,我注意到 https://github.com/flitbit/diff 库尚未列为解决方案.

After reviewing the existing answers, I noticed that the https://github.com/flitbit/diff library was not yet listed as a solution.

从我的研究来看,这个库在积极开发、贡献和解决不同对象的挑战方面似乎是最好的.这对于在服务器端创建差异并仅将更改的位传递给客户端非常方便.

From my research, this library seems to be the best in terms of active development, contributions and forks for solving the challenge of diffing objects. This is very handy for creating a diff on the server side and passing the client only the changed bits.

这篇关于如何获得两个 JavaScript 对象图之间差异的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆