Darthg8r
Darthg8r

Reputation: 12685

Instantiating a Backbone Model

I'm constantly getting an error when I instantiate a new instance of a model. Can anyone spy the error?

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

Script:

(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>

Upvotes: 1

Views: 1561

Answers (1)

freejosh
freejosh

Reputation: 11383

Remove the new keywords on the lines where you're extending the Model and View.

Upvotes: 2

Related Questions