2012-11-27 160 views
1

當我實例化模型的新實例時,我經常發生錯誤。任何人都可以偵測到錯誤?實例化骨幹模型

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> 

回答

2

在哪裏你擴大Model和View線取下new關鍵字。

+1

賓果,好眼睛 – Darthg8r