使用 Ext JS 进行 jQuery 深度复制?
我尝试过,但很惊讶我怎么不能用 ExtJS 做到这一点。让我用代码块来解释一下。
在 jQuery 中
console.clear(); var a = { b: 5, c: 4, o: { l: 2, p: 2 } } var b = { k: 4, l: 3, c: 5, o: { m: 2, l: 1 } } var ex = $.extend(true, a, b); console.dir(ex)
,这里是输出
ex = { a: { q: 2 }, b: 5, c: 5, o: { l: 1, p: 2, m: 2 } }
Ext apply、applyIf、copyTo 不会像这样工作。如何在 ExtJS 中生成输出?
提前致谢。
I've tried and surprised how could not I do with ExtJS. Let me explain with a code block.
In jQuery
console.clear(); var a = { b: 5, c: 4, o: { l: 2, p: 2 } } var b = { k: 4, l: 3, c: 5, o: { m: 2, l: 1 } } var ex = $.extend(true, a, b); console.dir(ex)
Here is the output
ex = { a: { q: 2 }, b: 5, c: 5, o: { l: 1, p: 2, m: 2 } }
Ext apply, applyIf, copyTo does not worked like this. How can I produce the output in ExtJS?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于最近的项目,我们改编了此示例代码以生成以下方法:
For a recent project, we adapted this sample code to produce the following method:
Ext 不支持深度复制。有 Ext.apply 和 Ext.applyIf ,但它们都仅适用于哈希映射的第一级,并且将覆盖而不是合并任何嵌入的数组或哈希。
事实上,文档明确指出 Ext.apply 用于配置对象,这并不重要,只是为了说明它并不意味着用作合并实用函数,尽管如果您只想合并第一层/深度。
Deep copying isn't supported in Ext. There are
Ext.apply
andExt.applyIf
but they both only work on the first level of a hash map and will override instead of merge any embedded arrays or hashes.In fact the docs explicitly state that Ext.apply is meant to work on config objects, not that it matters but it's just to illustrate that it's not meant to be used as a merge utility function although it basically could if you only want to merge the first level/depth.
使用 Ext.Object.merge()< /a> 方法,这正是您正在寻找的。
Use the Ext.Object.merge() method, that does exactly what you're looking for.