Backbone.history.start()发出错误

时间:2015-04-10 13:03:27

标签: 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

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

   });

1 个答案:

答案 0 :(得分:0)

我的猜测是你可能正在使用相当旧版本的jQuery,1.6或许?

1.6并不包含用于监听事件的on方法,因此我猜测当您调用Backbone.history.start()时,Backbone会在尝试执行时抛出错误:< / p>

Backbone.$(window).on('hashchange', this.checkUrl);

升级您的jQuery版本。如果你需要支持IE 6/7/8升级到jQuery 1.x,如果没有升级到2.x。