Backbone.js 主干路由器&x2B;咖啡脚本不起作用?
+我正在用主干网和咖啡脚本玩arround,试图让路由器启动并运行。执行以下代码时,init函数可以工作,但是当浏览localhost/#world/3时,什么也不会发生,尽管它应该记录一些东西Backbone.js 主干路由器&x2B;咖啡脚本不起作用?,backbone.js,router,Backbone.js,Router,+我正在用主干网和咖啡脚本玩arround,试图让路由器启动并运行。执行以下代码时,init函数可以工作,但是当浏览localhost/#world/3时,什么也不会发生,尽管它应该记录一些东西 App = start: -> new App.TestRouter Backbone.history.start App.TestRouter = Backbone.Router.extend routes: "world/:id": "testView"
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}"
有什么建议吗?我瞎了吗?
主干.history.start()
是一个函数,所以需要()
来执行它。否则,只会得到对函数本身的引用
App =
start: ->
new App.TestRouter
Backbone.history.start()
请参阅此实时JSFIDLE:
OT:这是我不喜欢咖啡脚本的一个原因。没有帕伦斯了!!!除了某些情况,你肯定会忘记。。。。