重新渲染后的Marionette ItemView事件

iBo*_*ozy 2 javascript backbone.js marionette

我第一次和Marionette一起玩.重新渲染ItemViews后,不会触发其事件.简单的例子:

App = new Marionette.Application;

App.addRegions({
    headerRegion: '#header',
    contentRegion: '#content',
});

App.addInitializer(function () {
    this.Views = {
        MainMenu : new MainMenuView(),
        ContentOne : new ContentOneView(),
        ContentTwo : new ContentTwoView(),
    };
});

App.addInitializer(function () {
    var self = this;
    var eva = self.vent;
    eva.listenTo(self.Views.MainMenu, 'content1', function () {
        self.contentRegion.show(self.Views.ContentOne);
    });
    eva.listenTo(self.Views.MainMenu, 'content2', function () {
        self.contentRegion.show(self.Views.ContentTwo);
    });
});

App.on('start', function () {
    var self = this;
    self.contentRegion.show(self.View.ContentOne);
});

App.start();
Run Code Online (Sandbox Code Playgroud)

重新渲染ContentOneView和ContentTwoView后,不会触发其事件.我做错了什么?

And*_*bbs 5

您遇到的问题region.show()是将关闭当前占用该区域的任何视图.这样做会取消视图的事件.在初始之后,region.show()您应该在视图上手动调用render.

您可以在此处看到此解释,在此处讨论此问题.