简体   繁体   English

在客户端深度克隆对象(GWT + Javascript)?

[英]Deep Cloning an object on the client side (GWT + Javascript) ?

I know of a Deep Cloning library in Java, which I use in my server side code. 我知道Java中的Deep Cloning库,该库在服务器端代码中使用。

However, right now I need to "deep clone" an object on the client side code. 但是,现在我需要在客户端代码上“深度克隆”一个对象。 I believe there's a Javascript framework that does this thing which is YUI3, however I am not sure how to use this with my GWT code. 我相信有一个执行此操作的Javascript框架就是YUI3,但是我不确定如何在我的GWT代码中使用它。

You could use JSNI to use YUI3 code from GWT Code, however you would have to include the whole YUI3 source in your GWT app which might be a litle bit inefficient if you only need the deep cloning functionality. 您可以使用JSNI来使用GWT代码中的YUI3代码,但是您必须将整个YUI3源代码包含在GWT应用程序中,如果您只需要深度克隆功能,则可能效率不高。
If you have the the source code for the deep cloning library for your java backend you might use it also on the GWT client if there are no external dependencies. 如果您拥有Java后端的深层克隆库的源代码,并且在没有外部依赖项的情况下,也可以在GWT客户端上使用它。
You can check out also these resources for more info: 您也可以查看以下资源以获取更多信息:

How can I deep copy an arbitrary object in GWT? 如何在GWT中深度复制任意对象?
GWT Overlay deep copy GWT叠加深层复制

Another option that I use is converting the Java object to JSON, and then converting back to a Java object. 我使用的另一个选项是将Java对象转换为JSON,然后再转换回Java对象。

Where this is not the cleanest way, there is answer to a different question that indicates that this is a faster way than the traditional clone() method (which is not supported in GWT). 如果这不是最干净的方法,那么可以回答一个不同的问题 ,该问题表明这是比传统的clone()方法(GWT不支持)更快的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM