3
我有點失落,所以任何幫助將不勝感激。 (我正在使用Backbone.js和CoffeeScript。)多個集合中的模型?
我有一組模型。他們都被放在MasterCollection
。
MasterCollection extends Backbone.Collection
model: Model
MasterCollection.add({#attributes of a new model})
我需要這些模型有時它們的屬性分批分離和處理。這些批次還需要具有相應的DOM視圖,可以顯示所有模型的數據。
Model extends Backbone.Model
initialize:() ->
#add the model to it's batch, batches are collections stored in an array
batches = ParentModel.get('baches')
#find the batch this model belongs in
for batch in batches
if batch = #the right one
batch.add(@toJSON)
Batch extends Backbone.Collection
changeAttributes:() ->
for model in @models
#change things about the model
- 當這個模型是由一批改變,這將更新
MasterCollection
模型? - 當我完成批量收集後,如何在不刪除其模型的情況下襬脫它?
- 我應該將這些批處理集合存儲在比數組更好的東西上嗎?他們應該成爲模特嗎?
由於我需要DOM綁定到創建新批次,因此將它們作爲集合中的模型會很好。
這是一個很好的方法來完成這種類型的事情嗎?
謝謝!
現在我想一批應該是一個BatchModel模型集合,想法? – fancy
也批量模型的集合。您可以在多個集合中添加模型,並且它可以工作,其事件將在屬於的所有集合中廣播。在其他作品中,請勿使用toJSON複製數據,只需執行batchCollection.add(this) – dira