问题
Native Array in Emberjs does not support deep copy? I saw it just returning sliced array in the copy method. Is it a bug?
回答1:
Currently, that's an improvement going on Ember, reported by @adamjmurray: https://github.com/emberjs/ember.js/issues/588
There's also a proposition to implement it. You can use it like this:
var NativeArray = Ember.Mixin.create(Ember.NativeArray, {
copy: function(deep) {
if (deep) {
return this.map(function(item){ return Ember.copy(item, true) });
} else {
return this.slice();
}
}
});
NativeArray.apply(Array.prototype);
回答2:
In Ember.Copyable the comments state that there should be a boolean parameter that if true would produce a deep copy, but obviously it's not implemented yet. You can always override it with your own method. Something like this would work for simple objects (note: untested so consider this pseudocode)
copy: function(deep) {
if(deep) return $.extend(true, [], this);
else return this._super();
}
来源:https://stackoverflow.com/questions/9693154/native-array-in-emberjs-does-not-support-deep-copy