Backbone Router has no method navigate

纵然是瞬间 提交于 2019-12-08 06:15:16

问题


Just wondering why my router has no method navigate?

I have new App.Router; called properly. And in my view I try to call my index view like so:

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) ;

}

I get the following error in Chrome Dev Tools:

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

I even tried to call navigate from the console and it doesnt seem to work either.

What am I doing wrong?


回答1:


You should call navigate on your router object. It seems you are calling it on the class itself.

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


myRouter.navigate('', true);


来源:https://stackoverflow.com/questions/15612087/backbone-router-has-no-method-navigate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!