2013-06-23 91 views
0

在的CollectionView骨幹木偶對象我的初始化函數,我做了以下內容:初始化的CollectionView與集合參考

this.collection_addresses = new AddressCollectionView({ 
    el: 'ul.addresses', 
    collection: options.user.get("addresses") 
}); 

然而AddressCollectionView每當options.user.get("addresses")引用的對象改變時從不更新,我馬里奧內特正在自動處理這個問題。用戶對象使用提取進行更新。有什麼想法嗎?

編輯#1 只是爲了澄清收集的觀點是這樣的

var AddressCollectionView = Backbone.Marionette.CollectionView.extend({ 
    itemView: AddressItemView, 
    tagName: 'ul' 
}); 

感謝。

+0

從文檔看來,您仍然需要「收聽」收集活動 –

+0

@AstDerek爲什麼? collectionview initailizer通常會監聽添加/刪除/重置 –

+0

您不會添加/刪除/重置該集合。您正在修改該集合的模型。 –

回答

0

從V1.0.3源代碼,這裏有的CollectionView偵聽

_initialEvents: function(){ 
    if (this.collection){ 
     this.listenTo(this.collection, "add", this.addChildView, this); 
     this.listenTo(this.collection, "remove", this.removeItemView, this); 
     this.listenTo(this.collection, "reset", this.render, this); 
    } 
    }, 

甲的CollectionView接受一個I​​temView控件視圖對象定義,(不是一個實例)的事件。此itemView使用collectionview中集合中每個項目的模型進行初始化。我會擴展木偶的itemview類,然後在你的模型上聽你的更改事件,並將該itemview視圖對象定義(不是實例)注入collectionview。

+0

我已經有了一個地址收集類,我在 –

+0

上面添加了它,你itemView需要在它的初始化塊中監聽模型改變事件,然後你應該完成。 –