0

+我在玩骨干网和咖啡脚本,试图让路由器启动并运行。执行以下代码,init 函数可以工作,但是在浏览 localhost/#world/3 时没有任何反应,尽管它应该记录一些东西....

App =
  start: ->
    new App.TestRouter
    Backbone.history.start

App.TestRouter = Backbone.Router.extend
  routes: 
    "world/:id": "testView"

  initialize: ->
    new App.TestView
    console.log "Router init"

  testView: (id) ->
    console.log "testing! #{id}"

这里有什么建议吗?我瞎了吗?

4

1 回答 1

2

Backbone.history.start()是一个函数,所以你需要()执行它。否则,您只是获得对函数本身的引用。

App =
  start: ->
    new App.TestRouter
    Backbone.history.start()

看到这个现场 jsFiddle:

http://jsfiddle.net/edwardmsmith/6pNLv/8/

于 2012-09-06T14:25:28.507 回答