林與收集和模型工作:臨時骨幹收集編輯模式
在一個地方var StuffCollection = Backbone.Collection;
var StuffModel = Backbone.RelationalModel;
我作出這樣的收集與模型實例:
var stuffCollection = new StuffCollection();
// do stuff here to load a bunch of models
在另一個地方,我想克隆該集合編輯而不編輯原始:
var tempStuffCollection = new StuffCollection();
tempStuffCollection.reset(stuffCollection.models);
// do stuff here to edit the collection
但是當我編輯m odels在tempStuffCollection他們編輯stuffCollection 所以不是我想這樣的:
var tempStuffCollection = new StuffCollection();
tempStuffCollection.reset(stuffCollection.toJSON());
// do stuff here to edit the collection
所以它似乎像所有的引用都被刪除......但不!當我在tempStuffCollection中編輯模型時,它仍然在stuffCollection中更改它們!
我該如何分離兩個模型集?
您的意思是:tempStuffCollection.add(new Backbone.Model(model.toJSON())); – Kev
確實:)進行編輯。對於那個很抱歉。 –
這不是爲我工作,但我也使用骨幹關係模型...我得到這個錯誤:不能實例化每個類型相同的ID多個Backbone.RelationalModel! – Kev