Backbone.history.start() 报错
Backbone.history.start() giving out error
出现错误:
Uncaught TypeError: undefined is not a function
匿名函数错误指向
Backbone.history.start()
下面是我的index.html和main.js.
我有一种感觉,jquery、下划线和 backbone 文件可能无法正确加载,因此会发生此错误
非常感谢 backbone.Any 帮助初学者
使用的版本:
underscore - 1.8.3
backbone - 1.1.2
index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="/stylesheets/style.css">
<script src="javascripts/jquery.min.js"></script>
<script src="javascripts/json2.js"></script>
<script src="javascripts/underscore-min.js"></script>
<script src="javascripts/backbone-min.js"></script>
<script src="javascripts/main.js"></script>
</head>
</html>
main.js
$(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();
});
我猜你可能使用的是相当旧的 jQuery 版本,也许是 1.6?
1.6 不包含用于侦听事件的 on
方法,所以我猜想当您调用 Backbone.history.start()
时,Backbone 会在尝试执行时抛出错误:
Backbone.$(window).on('hashchange', this.checkUrl);
升级您的 jQuery 版本。如果需要支持IE 6/7/8升级到jQuery1.x,如果不支持升级到2.x.
出现错误:
Uncaught TypeError: undefined is not a function
匿名函数错误指向
Backbone.history.start()
下面是我的index.html和main.js.
我有一种感觉,jquery、下划线和 backbone 文件可能无法正确加载,因此会发生此错误 非常感谢 backbone.Any 帮助初学者
使用的版本:
underscore - 1.8.3
backbone - 1.1.2
index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="/stylesheets/style.css">
<script src="javascripts/jquery.min.js"></script>
<script src="javascripts/json2.js"></script>
<script src="javascripts/underscore-min.js"></script>
<script src="javascripts/backbone-min.js"></script>
<script src="javascripts/main.js"></script>
</head>
</html>
main.js
$(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();
});
我猜你可能使用的是相当旧的 jQuery 版本,也许是 1.6?
1.6 不包含用于侦听事件的 on
方法,所以我猜想当您调用 Backbone.history.start()
时,Backbone 会在尝试执行时抛出错误:
Backbone.$(window).on('hashchange', this.checkUrl);
升级您的 jQuery 版本。如果需要支持IE 6/7/8升级到jQuery1.x,如果不支持升级到2.x.