问题
I am trying to follow along with the tutorial I purchased from this site: http://www.backbonerails.com/
I am following along with the 5th episode of the series, "Getting Up and Running - Part 1".
At about the 46:52 mark of the video he has this code for "list_controller.js.coffee".
@Demo.module "HeaderApp.List", (List, App, Backbone, Marionette, $, _) ->
List.Controller =
listHeader: ->
console.log "header"
When I have this...everything works...the console reads "header".
At about the 47:20 mark of the video he changes it to this:
@Demo.module "HeaderApp.List", (List, App, Backbone, Marionette, $, _) ->
List.Controller =
listHeader: ->
headerView = @getHeaderView()
App.headerRegion.show headerView
getHeaderView: ->
new List.Header
When he changes the code, I am supposed to be able to see the header in my browser, but I don't. In firebug, I get the error:
TypeError: List.Header is not a constructor
return new List.Header;
The other relevant code is here:
list_header.jst.eco
<div id="header" class="navbar">
<div class="navbar-inner">
<div class="container">
<div class="row">
<div class="pull-left">
<span class="brand">Backbone Poop</span>
</div>
<ul class="nav pull-right">
<li class="active">
<a href="#">link 1</a>
</li>
<li>
<a href="#">link 2</a>
</li>
<li>
<a href="#">link 3</a>
</li>
</ul>
</div>
</div>
</div>
</div>
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()
UPDATE
So I was messing around with the code...don't think I changed anything...but I got the console message, "header", to appear again. But now firebug says:
uncaught exception: Template undefined not found!
I've checked to make sure all of my path stuff with the directory structure is correct, couldn't see any problems. Any ideas?
MORE INFO
I get the same error in chrome's console. But when I inspect the error (click the arrow) and scroll to the (undefined function) and click its corresponding "app.js:14" link...I can see this:
App.addInitializer(function() {
App.module("HeaderApp").start();
return App.module("FooterApp").start();
});
It looks the "HeaderApp" isn't getting returned...important?
来源:https://stackoverflow.com/questions/16820407/backbone-rails-typeerror-list-header-is-not-a-constructor