我是.clone() - 一个集合,这样我就可以在它上面使用拼接循环而不会干扰原始集合。模型是克隆的数组原件还是副本?
我需要的是包含原始模型的数组副本。
感谢您的任何信息!
答案 0 :(得分:8)
您将获得与包含在相同类型的新集合中的源集合相同的模型。
这是collection.clone:
的实现 clone: function() {
return new this.constructor(this.models);
},
或者如果您更喜欢深度克隆,请覆盖Backbone.Collection.clone
clone: function(deep) {
if(deep) {
return new this.constructor(_.map(this.models, function(m) { return m.clone(); }));
}else{
return Backbone.Collection.prototype.clone();
}
}