Backbone.js 导航主干没有方法';导航';
我想使用带有导航的路线,但我有一个错误Backbone.js 导航主干没有方法';导航';,backbone.js,routes,router,Backbone.js,Routes,Router,我想使用带有导航的路线,但我有一个错误 (function(){ window.App = { Models: {}, Collections: {}, Views: {}, Routers: {} }; App.Router = Backbone.Router.extend({ routes: { "/case-projet/:projet": "caseProjet" }, showPage: function(pa
(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开发工具中:
未捕获的TypeError:对象函数(){return parent.apply(this,arguments);}没有方法“navigate”
我试着回答,但这不起作用
我为什么会犯这个错误
Tks:)更改呼叫
应用程序路由器。导航(…)
到主干网。历史记录。导航(…)
或者,您可以为创建的
new App.Router()
实例设置一个变量,然后对该实例调用navigate
函数。您的代码正在尝试调用类定义上的导航
;您需要一个类的实例。看起来很像,我知道,但这不起作用:/Tks!很好!对你来说,最好的做法是什么?太好了,很高兴听到这个消息。我自己使用Backbone.history.navigate
,我在很多其他代码中也看到了这一点。在我的应用程序中,它通过主干网
全局网络随处可用,因此我不必让我自己的路由器实例从其他模块上可用。好的,太完美了!谢谢