jQuery比较两个序列化对象 [英] jQuery compare two serialized objects

查看:83
本文介绍了jQuery比较两个序列化对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的插件包含事件API start stop 。当我开始在网格中拖动元素时,它会创建一个当前状态下所有数据的序列化数组。

I am using a plugin that has an API for events start and stop. When I start dragging the element in the grid, It creates a serialized array of all the data in its current state.

当项目被删除时,它还会创建一个序列化的数据数组。

When the item is dropped, it also creates a serialized array of data.

我想比较这两组数据,看它是否完全改变了。我不想触发数据库调用来更新网格放置,如果用户开始拖动某些内容然后将其放回到之前的位置。

I want to compare these two sets of data to see if it has changed at all. I don't want to trigger a database call to update the grid placement if the user started dragging something and then put it back in its previous spot.

我试过比较他们就像使用 == 一样,我在比较之前首先使用了 jSON.stringify 但是已经读过它了可以提供混合的结果。

I have tried comparing them as is using == and I have also used jSON.stringify on them first before comparing but have read that it could provide mixed results.

有没有比较容易比较这样的两个对象的方法?

Is there an easy to way to compare two objects like this?

推荐答案

== 检查对象的引用是否相等(不比较内容)。

== checks if object's references are equal (doesn't compares content).

对于深层对象比较,您可以使用 lodash的isEqual()

For deep object comparison, you can use lodash's isEqual().

这篇关于jQuery比较两个序列化对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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