2013-03-09 49 views
0

我有一個區域App.modalRegion,我展示TopicView,一個CompositeView中,顯示在sidebar講座鏈接,並點擊一個鏈接時播放講座視頻content區域的列表。一切工作正常,但VideoItemView未被關閉,當另一個鏈接被點擊。關閉ItemView控件不提線木偶的RegionManager

我的問題是:當視頻內容在'.link'點擊改變,有沒有(這些木偶的神奇方式中的一種)以前VideoItemView可以被關閉不使用App.modalRegion區域內的子區域和佈局。下面的代碼:

App.modalRegion.show(new TopicView({ model: topicModel })); 

TopicView = new Backbone.Marionette.CompositeView.extend({ 

    template: tpls.TopicTpl, 

    ui: { 
    sidebar: "#topic-sidebar", 
    content: "#topic-content" 
    }, 

    initialize: function(){ 
    this.listenTo(this.model, "change", this.render); 
    }, 

    onRender: function(){ 
    this.showContent(); 

    var collection = this.model.get('lectures'), 
     that = this; 

    this.ui.sidebar.on('click','.link',function(e) { 
     e.preventDefault(); 
     var sno = $(this).data("sno"); 

     var vid = new VideoItemView({ 
     model: collection.get(sno), 
     lec_sno: sno 
     }); 

     that.ui.content.html(
     vid.render().el 
    ); 
    }); 
    }, 

    showContent : function() { 

    var list = new LectListCol({ 
     collection: this.model.get('lectures') 
    }); 

    this.ui.sidebar.html(
     list.render().el 
    ); 
    } 

}); 

回答

0

我將一個屬性添加到您的TopicView會引用您的currentVideoItemView

就在呈現新的VideoItemView之前,您需要檢查currentVideoItemView是否爲VideoItemView的實例。

,那麼你會呼籲currentVideoItemViewclose方法,使您的新VideoItemView,然後重新設置currentVideoItemView