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.
For a recent project, we adapted this sample code to produce the following method:
Ext.deepCopy = function(p, c) {
c = c || (p.constructor === Array ? [] : {});
for (var i in p) {
if (typeof p[i] === 'object' && p[i] !== null) {
c[i] = p[i].constructor === Array ? [] : {};
Ext.deepCopy(p[i], c[i]);
} else {
c[i] = p[i];
}
}
return c;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With