1
交換childview是否可以動態地改變childView中的CollectionView木偶,在collectionVeiw
類似:
//model
var FooBar = Backbone.Model.extend({
selected: false,
});
//collection view
var MyCollectionView = Marionette.CollectionView.extend({
getChildView: function(item) {
if (item.selected === true) {
return FooView;
}
else {
return BarView;
}
},
// trigger from child view that should swap views
// model.selected is now true
triggerFromChildView: function (childview, model) {
//how to destroy childview and to re-create one for this model?
}
});
謝謝你的想法。我的第一個想法是「複製」刪除模型(沉默),然後再將該模型添加到集合中(這將觸發渲染,並且比較器將新視圖放置在舊模型的相同位置) – InTry