导航骨干没有方法导航'

时间:2014-03-19 18:08:53

标签: backbone.js routes router

我想使用路由导航但我有错误。

(function(){

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

App.Router = Backbone.Router.extend({
    routes: {
        "/case-projet/:projet": "caseProjet"
    },
    showPage: function(page){
        //hide all pages
        this.hidePages();
        //show passed page by selector
        $(page).show();
    },
    caseProjet: function (e) {
        this.showPage('div#partech-introduction');
    }

});

new App.Router;
Backbone.history.start();

App.Views.Incentive = Backbone.View.extend({
    el: $("#projet-page"),
    caseStudyContainer: $("#projet-page"),
    caseStudyElem: $('section[data-projet-page="Incentive"]'),
    initialize: function () {
        $("#Incentive a.OpenProject").on("click", this.enterProjectAnim)
    },
    enterProjectAnim: function () {
        var e = this;
        App.Router.navigate("/case-projet/Incentive", {trigger: true})
        , $("#homepage").css("display", "none")
        , e.caseStudyElem.css({ display: "block" })
        , $("#partech-introduction").addClass("active")
    }
});

})();

在Chrome开发工具中:

Uncaught TypeError:Object function(){return parent.apply(this,arguments);没有方法'导航'

我尝试了Backbone Router has no method navigate的回复,但这不起作用。

为什么我有这个错误?

Tks:)

1 个答案:

答案 0 :(得分:0)

将来电App.Router.navigate(...)更改为Backbone.history.navigate(...)

或者,您可以将变量设置为您创建的new App.Router()实例,然后在该实例上调用navigate函数。您的代码试图在类定义上调用navigate;你需要一个类的实例。

相关问题