1

我正在使用 Marionette.Backbone 创建一个 web 应用程序,并且我得到了一个创建布局并向其中添加三个子视图的模块。

布局渲染良好,但区域未填充每个子视图。我错过了什么。我在控制台中没有错误。

这是我的控制器:

@Appic.module "ProjectsApp.Add", (Add, App, Backbone, Marionette, $, _) ->

    Add.Controller =

        addProject: ->
            @layout = @getLayoutView()

            @layout.on "show", =>
                @showLeft
                @showContent
                @showRight

            App.mainRegion.show @layout

        showLeft: ->
            leftView = @getLeftView
            @layout.leftRegion.show leftView

        showContent: ->
            contentView = @getContentView
            @layout.contentRegion.show contentView

        showRight: ->
            rightView = @getRightView
            @layout.rightRegion.show rightView

        getLeftView: ->
            new Add.Left

        getContentView: ->
            new Add.Form

        getRightView: ->
            new Add.Right

        getLayoutView: ->
            new Add.Layout

这是我的模块视图部分

@Appic.module "ProjectsApp.Add", (Add, App, Backbone, Marionette, $, _) ->

    class Add.Layout extends App.Views.Layout
        template: "projects/add/templates/add_layout"

        regions:
            leftRegion: "#left-region"
            contentRegion: "#content-region"
            rightRegion: "#right-region"

    class Add.Left extends App.Views.ItemView
        template: "projects/add/templates/_left"

    class Add.Right extends App.Views.ItemView
        template: "projects/add/templates/_right"

    class Add.Form extends App.Views.ItemView
        template: "projects/add/templates/_form"
4

1 回答 1

0

您正在分配一个指向函数的指针,而不是函数导致您的 show 方法。尝试:

    showLeft: ->
        leftView = @getLeftView()
        @layout.leftRegion.show leftView

    showContent: ->
        contentView = @getContentView()
        @layout.contentRegion.show contentView

    showRight: ->
        rightView = @getRightView()
        @layout.rightRegion.show rightView
于 2013-04-19T11:07:10.413 回答