Backbone.js Backbone.history.start()发出错误
获取错误:Backbone.js Backbone.history.start()发出错误,backbone.js,backbone-routing,Backbone.js,Backbone Routing,获取错误: Uncaught TypeError: undefined is not a function 匿名函数错误指向 Backbone.history.start() 下面是我的index.html和main.js 我有一种感觉,jquery、下划线和主干文件可能没有正确加载,因此发生了此错误 这是个初学者,非常感谢您的帮助 使用的版本: underscore - 1.8.3 backbone - 1.1.2 index.html 我猜您可能正在使用非常旧的jQuery版本,可能是
Uncaught TypeError: undefined is not a function
匿名函数错误指向
Backbone.history.start()
下面是我的index.html和main.js
我有一种感觉,jquery、下划线和主干文件可能没有正确加载,因此发生了此错误
这是个初学者,非常感谢您的帮助
使用的版本:
underscore - 1.8.3
backbone - 1.1.2
index.html
我猜您可能正在使用非常旧的jQuery版本,可能是1.6 1.6不包括侦听事件的on方法,因此我猜当您调用Backbone.history.start时,Backbone在尝试执行以下操作时会抛出错误:
Backbone.$(window).on('hashchange', this.checkUrl);
升级jQuery的版本。如果您需要支持IE6/7/8升级到jQuery 1.x,如果不需要升级到2.x。您应该在console中单击它所指的行。它可能会提供更多关于确切线路的信息,如果applicable@Seth:是的,我是这样做的,这就是我理解Backbone.history.start的原因:它所指的行是Backbone.history.start?您应该尝试在其上放置一个断点,并单步执行所有函数调用,以查看其中断的位置。
$(document).ready(function(){
var Theater = {
Models: {},
Collections: {},
Views: {},
Templates:{},
Routers:{}
}
Theater.Models.Movie = Backbone.Model.extend({});
Theater.Collections.Movies = Backbone.Collection.extend({
model: Theater.Models.Movie,
url: "/json",
initialize: function(){
console.log("Movies initialize")
}
});
Theater.Routers = Backbone.Router.extend({
initialize:function(){ console.log("defaultRoute");},
routes: {
"": "defaultRoute"
},
defaultRoute: function () {
console.log("defaultRoute");
}
});
console.log("gonna call approuter");
var appRouter = new Theater.Routers();
Backbone.history.start();
});
Backbone.$(window).on('hashchange', this.checkUrl);