【问题标题】:Marionette: Uncaught ReferenceError木偶:未捕获的引用错误
【发布时间】:2014-07-29 18:33:58
【问题描述】:

我正在研究 Backbone,使用 Marionette 和 Rails 作为后端,使用截屏视频,我遇到了这个错误:

Uncaught ReferenceError: FooterApp is not defined 

我的 app.js.coffee 代码:

@Demo = do (Backbone, Marionette) ->

    App = new Backbone.Marionette.Application

    App.addRegions
        headerRegion: "#header-region"
        mainRegion: "#main-region"
        footerRegion: "#footer-region"

    App.addInitializer ->
        App.module("FooterApp").start()
        #App.execute "footer:show"

    App.on "initialize:after", ->
        if Backbone.history
            Backbone.history.start()

    App

footer_app.js.coffee

@Demo.module "FooterApp", (FooterApp, App, Backbone, Marionette, $, _) ->
  @startWithParent = false

    API = 
        showFooter: ->
            FooterApp.Show.Controller.showFooter()

    FooterApp.on "start", ->
        API.showFooter()

show_controller.js.coffee

@Demo.module "FooterApp.Show", (Show, App, Backbone, Marionette, $, _) ->

    Show.Controller = 

        showFooter: ->
            console.log 'test'

我花了很多时间找出问题所在,但仍然没有任何线索..

【问题讨论】:

    标签: backbone.js coffeescript marionette


    【解决方案1】:

    在您的代码中,您尚未初始化控制器,它应该更像这样

    API = 
        showFooter: ->
            new FooterApp.Show.Controller
    

    然后在你的页脚控制器中你可以有一个初始化函数来显示它

    initialize: ->
        console.log 'test'
    

    【讨论】:

      猜你喜欢
      • 2014-11-02
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 2013-10-27
      • 2014-10-11
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多