1

我正在尝试在我的应用程序中使用 MVC 流来构建我的代码。我正在尝试在我的 marionette.controller 中的 marionette 应用程序实例中显示创建的布局,如下所示..

  1. 谁能告诉我在控制器中显示或更改布局的正确方法是否正确?如果不是,那么正确的方法是什么。

我的控制器

define([ 'marionette', 'app', 'index_view' ], function( Marionette, App, IndexView ) {
console.log("Inside...ViewFlow Controller.");
var ViewFlow_Controller = Marionette.Controller.extend({
    loadIndex : function() {
        console.log("Inside...Load Index Method.");
        App.main.show( new IndexView() );
    }
});
return new ViewFlow_Controller();
});

我的 IndexView 是这样的

define(['app', 'helper', 'templates'],
function (App, Helper, templates){
console.log("Inside...Index View.");
App.Page_Index = (function(){
    var Page_Index = {};

    var _pageName = 'IndexPage';        
    var _pageLayout = Helper.newPageLayout({
        name:_pageName,
        panelView:      Helper.newPanelView(),
        headerView:     Helper.newHeaderView({name:_pageName, title:'Welcome to the Index Page'}),
        contentView:    Helper.newContentView({name:_pageName, template: templates.content_index}),
        footerView:     Helper.newFooterView({name:_pageName, title:'IndexPage Footer'})
    });

  return Page_Index;

})();

return App.Page_Index;
});

我的助手返回给我 App_Layout 实例。但它不起作用,它给了我一个错误

Uncaught TypeError:object is not a function   viewflow_controller.js:12

请帮帮我。

如果您想参考完整代码或贡献代码,可以在此处找到代码。

提前致谢。

4

1 回答 1

1

The code on GitHub seems to contain only empty files (aside from the libraries), so I'm going to assume Helper returns a layout instance (which you seem to have indicated, saying it returned an App_Layout instance).

It looks like you're using layouts wrong. The way to use layouts is basically:

  1. Create a layout instance with regions (e.g.) panelRegion and contentRegion
  2. Create view instances that will be displayed in the layout (e.g.) panelViewInstance and contentViewInstance
  3. Write a handler to show your views when the layout itself is shown.

The handler should look like this:

  myLayout.on("show", function(){
      myLayout.panelRegion.show(panelViewInstance);
      myLayout.contentRegionshow(contentViewInstance);
  });

Then, show that layout in one of your app's regions:

  MyApp.mainRegion.show(myLayout);

The documentation on layouts is here: https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.layout.md

You can learn more on using layouts and structuring your code in my book on Marionette.

于 2013-06-02T05:22:00.640 回答