实例化骨干模型

时间:2012-11-27 02:20:33

标签: backbone.js

当我实例化模型的新实例时,我经常遇到错误。任何人都可以监视错误吗?

Uncaught TypeError: Object [object Object] has no method 'apply' 

脚本:

(function() {
    var Ticket = new Backbone.Model.extend({
        urlRoot: "/api/tickets",
        Subject: "",
        Created: null
    });

    var TicketView = new Backbone.View.extend({
        Model: Ticket,
        el: "body",
        render: function() {
            return this.$el.html(this.Model.Subject);
        }
    });

    // Error here
    var t = new Ticket();
    var tv = new TicketView({ model: t });

    tv.render();

})()

HTML:

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js" type="text/javascript"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script>
</head>
<body>
    <div>
        <div id="Main">Main</div>
    </div>
        <script type="text/javascript" src="/Scripts/Home_Index.js"></script>

</body>
</html>

1 个答案:

答案 0 :(得分:2)

删除您要扩展模型和视图的行上的new个关键字。