javascript - backbone model cannot fetch any data -


here're simplified codes

var playermodel = backbone.model.extend();  var playerprofileview = backbone.view.extend({ model : new playermodel({url: "http://mysite.com/api/getpalyer.php"}), render: function(){ this.model.fetch(); } }); 

the system keeps giving me error message

uncaught error: "url" property or function must specified

i totally have no idea what's wrong code.

here's backbone#model's constructor:

var model = backbone.model = function(attributes, options) { 

so see, options should given second argument. here you're passing url attribute (try this.get('url') verify that).

change to:

model : new playermodel(null, {url: "http://mysite.com/api/getpalyer.php"}); 

another thing:

also, declaring new object in class definition (new playermodel({url: "http://mysite.com/api/getpalyer.php"}),) result in having single instance of object shared objects (ie playerprofileview share single instance of playermodel). reason behind it's evaluated when class created , put in prototype of class.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -