2013-08-26 81 views
0

我無法獲取簡單的應用示例路由。我正在使用骨幹網上的寶石。Backbone.js:未達到路由器回調

這裏是我的App.js.coffee:

window.App = 
     Models: {} 
     Collections: {} 
     Views: {} 
     Routers: {} 

$(document).ready -> 
    MyRouter = Backbone.Router.extend(
     routes: 
     '' : 'index' 

     index: -> 
      console.log("Inside router") 
      new App.Views.HomeIndex() 
    ) 
    router = new MyRouter 
    Backbone.history.start 
    console.log(router.routes[Backbone.history.fragment]) 

路由器從未達到的指數回調的觀點是從來沒有顯示。

這裏是由Rails的渲染HTML頁面:

<!DOCTYPE html> 
<html> 
<head> 
    <title>App</title> 
    <link href="/assets/application.css?body=1" media="screen" rel="stylesheet" /> 
    <script src="/assets/jquery.js?body=1"></script> 
<script src="/assets/jquery_ujs.js?body=1"></script> 
<script src="/assets/underscore.js?body=1"></script> 
<script src="/assets/backbone.js?body=1"></script> 
<script src="/assets/app.js?body=1"></script> 
<script src="/assets/homes/index.js?body=1"></script> 
<script src="/assets/models/home.js?body=1"></script> 
<script src="/assets/collections/homes.js?body=1"></script> 
<script src="/assets/views/homes/homes_index.js?body=1"></script> 
<script src="/assets/routers/homes_router.js?body=1"></script> 
<script src="/assets/routers/homes_routers.js?body=1"></script> 
<script src="/assets/application.js?body=1"></script> 
    <meta content="authenticity_token" name="csrf-param" /> 
<meta content="sA25aKKc/j2EJL6k8J0gm8SxGU2mHRhH8Sb6Sye81Ac=" name="csrf-token" /> 
</head> 
<body> 

<div id="app"></div> 

</body> 
</html> 

什麼我需要做的正確實例化的骨幹路由器,並得到路由到我的意見?

+0

除非你認爲從它的構造函數呈現本身,你不叫渲染的任何地方。 – ssube

回答

0

看起來你只需要撥打Backbone.history.start而不是簡單地引用它。這只是引用功能:

Backbone.history.start 

這稱之爲:

Backbone.history.start() 

當你提供一些參數的函數調用括號是唯一可選的。

演示:http://jsfiddle.net/ambiguous/hUZUV/

+0

你完全正確。不能相信我錯過了!非常感謝! – Sly