2013-03-25 72 views
1

只是想知道爲什麼我的路由器沒有方法導航?我的new App.Router;正確調用。在我看來,我試着打電話給我的索引視圖,像這樣:骨幹路由器沒有方法導航

addTrip: function(e){ 

    e.preventDefault() ; 

    //Adding to collection 
    var newTrip = this.collection.create({ 
     title: this.$('#new_trip #title').val(), 
     where: this.$('#new_trip #where').val(), 
     desc: this.$('#new_trip #desc').val(), 
     rating: this.$('#new_trip .active').text() 
    }, { wait: true }) ; 

    if(newTrip.validationError){ 
     this.errorReport(newTrip.validationError) ; 
    } 

    this.clearForm() ; 

    //Navigate to home route 
    App.Router.navigate('', true) ; 

} 

我得到的Chrome瀏覽器開發工具以下錯誤:

Uncaught TypeError: Object function(){ return parent.apply(this, arguments); } has no method 'navigate'

我甚至試着打從控制檯導航和它似乎也沒有工作。

我在做什麼錯?

+0

你怎麼聲明'App.Router'? – neebz 2013-03-25 10:20:06

回答

9

您應該調用導航對象的路由器。看來你是在課堂上自己調用它。

App.myRouter = new Backbone.Router() //or if you have your own base router class App.myRouter = new App.Router() 


myRouter.navigate('', true); 
+0

我在'index.html'中聲明瞭我的路由器,但需要在我的方法中重新聲明它。謝謝@nEEbz – 2013-04-16 06:34:45

+0

使用路由器的實例我仍然無法觸發.navigate(myPath)。它在我調用Backbone.history.navigate(myPath)時起作用。 – Micros 2013-07-29 13:55:38