2014-11-03 91 views
1

我有這樣的佈局視圖:呼叫'上木偶LayoutView區域show`

var appLayoutView = Backbone.Marionette.LayoutView.extend({ 
    template: function() { 
     return "some template string"; 
    }, 
    regions: { 
     notify: "[data-region='Notify']" 
    }, 
    onShow: function() { 
     this.regions.notify.show(new notifyView()); 
    } 
}); 

我稱之爲像這樣:

mainLayout.app.show(appLayout); 

那麼理想,我想,當我運行上面(主要是當佈局視圖被放入DOM時)notifyView被渲染到「通知」區域。但this.regions.notify只是一個字符串。我怎樣才能達到我在這裏想要做的?基本上在Layout View類中具有「notify」的呈現邏輯,而不是從調用行進行控制。

回答

1

我找不到顯示此得到了其中添加任何文檔,但LayoutView應該有一個getRegion方法: https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.layoutview.js#L74

使你的代碼看起來像:

var appLayoutView = Backbone.Marionette.LayoutView.extend({ 
    template: function() { 
     return "some template string"; 
    }, 
    regions: { 
     notify: "[data-region='Notify']" 
    }, 
    onShow: function() { 
     this.getRegion('notify').show(new notifyView()); 
    } 
}); 
+0

Awhhhhh yisS基因!會放棄一下 – benhowdle89 2014-11-03 20:33:56