尝试按照 Ryan Bates Backbone.js 教程构建抽奖应用程序,但我已经遇到了第一段代码的问题。在 application.js 的 init 函数中,他初始化了应该触发警报“主页”的 Raffler 路由的新实例,但我在 Firebug 中收到以下错误,我不明白
entries.js:5Uncaught ReferenceError: Raffler is not defined
entry.js:15Uncaught ReferenceError: Backbone is not defined
entries.js:23Uncaught ReferenceError: Backbone is not defined
index.js:17Uncaught ReferenceError: Backbone is not defined
application.js:7Uncaught SyntaxError: Invalid regular expression: missing /
raffler.js:9Uncaught TypeError: undefined is not a function
有什么想法可以解决这个问题吗?
javascripts/raffler/application.js
window.Raffler =
Models: {}
Collections: {}
Views: {}
Routers: {}
init: ->
new Raffler.Routers.Entries()
Backbone.history.start()
$(document).ready ->
Raffler.init()
路由器/条目.js
class Raffler.Routers.Entries extends Backbone.Router
routes:
'': 'index'
index: ->
alert "home page"
更新
在我运行生成器//= require_tree .
之后,紧接着 require jquery_ujs,我发现(我认为)是导致一些问题的原因。但是,我现在已将其移至底部,但仍然出现此错误
Raffler.Routers.Entries is not a constructor
[Break On This Error]
new Raffler.Routers.Entries();
应用程序.js
//= require jquery
//= require jquery_ujs
//= require underscore
//= require backbone
//
//= require .//raffler
//
//= require_tree ../templates/
//= require_tree .//models
//= require_tree .//collections
//= require_tree .//views
//= require_tree .//routers
//= require_tree .