我想通過這個系列跟着一起:未捕獲的異常:模板未定義,沒有找到,引發ReferenceError:骨幹沒有定義
http://www.backbonerails.com/series/engineering_single_page_apps
我在第5集,在大約48分鐘大關。當我刷新頁面在瀏覽器中,我得到這個Firebug控制檯:
uncaught exception: Template undefined not found
我試圖在http://coffescript.org運行我的代碼,我得到這個錯誤:
ReferenceError: Backbone is not defined
我我不確定,但我猜測上述錯誤發生是因爲coffescript.org控制檯不知道Backbone是什麼。
下面是相關代碼:
show_controller.js.coffee
@Demo.module "FooterApp.Show", (Show, App, Backbone, Marionette, $, _) ->
Show.Controller =
showFooter: ->
console.log "footer"
footerView = @getFooterView()
App.footerRegion.show footerView
getFooterView: ->
new Show.Footer
與上面的代碼,我注意到在「頁腳」沒有出現,因爲它應該控制檯。所以也許控制器出了問題?或者在「showFooter」方法中。
list_controller.js.coffee
@Demo.module "HeaderApp.List", (List, App, Backbone, Marionette, $, _) ->
List.Controller =
listHeader: ->
console.log "header"
headerView = @getHeaderView()
App.headerRegion.show headerView
getHeaderView: ->
new List.Header
與上面的代碼,I DO註釋是「頭」,在控制檯出現,如此看來一切正常與HeaderApp。
show_view.js.coffee
@Demo.module "FooterApp.Show", (Show, App, Backbone, Marionette, $, _) ->
class Show.Footer extends Marionette.ItemView
template: "footer/show/templates/show_footer"
list_view.js.coffee
@Demo.module "HeaderApp.List", (List, App, Backbone, Marionette, $, _) ->
class List.Header extends Marionette.ItemView
template: "header/list/templates/list_header"
header_app.js.coffee
@Demo.module "HeaderApp", (HeaderApp, App, Backbone, Marionette, $, _) ->
@startWithParent = false
API =
listHeader: ->
HeaderApp.List.Controller.listHeader()
HeaderApp.on "start", ->
API.listHeader()
footer_app.js.coffee
@Demo.module "FooterApp", (FooterApp, App, Backbone, Marionette, $, _) ->
@startWithParent = false
API =
showFooter: ->
FooterApp.Show.Controller.showFooter()
FooterApp.on "start", ->
API.showFooter()
renderer.js.coffee
@Demo.module "FooterApp", (FooterApp, App, Backbone, Marionette, $, _) ->
@startWithParent = false
API =
showFooter: ->
FooterApp.Show.Controller.showFooter()
FooterApp.on "start", ->
API.showFooter()
app.js.coffee
console.log @
@Demo = do (Backbone, Marionette) ->
App = new Marionette.Application
App.addRegions
headerRegion: "#header-region"
mainRegion: "#main-region"
footerRegion: "#footer-region"
App.addInitializer ->
App.module("HeaderApp").start()
App.module("FooterApp").start()
App.on "initialize:after", ->
if Backbone.history
Backbone.history.start()
App
的application.js
//= require jquery
//= require lib/underscore
//= require lib/backbone
//= require lib/marionette
//= require_tree ./backbone/config
//= require backbone/app
//= require_tree ./backbone/apps
應用。CSS
@import "twitter/bootstrap";
@import "apps/base";
@import "apps/header";
@import "apps/footer";
這裏是目錄結構:
app
assets
javascripts
backbone
apps
footer
show
templates
show_footer.jst.eco
show_controller.js.coffee
show_view.js.coffee
footer_app.js.coffee
header
list
templates
list_header.jst.eco
list_controller.js.coffee
list_view.js.coffee
header.app.js.coffee
config
marionette
renderer.js.coffee
app.js.coffee
application.js
stylesheets
application.css
如果我所有的路徑東西聲明的基礎上正確我的目錄結構我想知道。
感謝您的幫助,我會熱切期待您的回覆。