Wednesday, 15 January 2014

javascript - Backbone uncaught error: -



javascript - Backbone uncaught error: -

in chrome console says there error backbone - uncaught error: "url" property or function must specified

i able prepare problem replacing backbone.js script version 1.1.2 1.0.0. can explain why newest version of backbone giving me error older version doesn't?

is there wrong in syntax below i'm trying set collection url api address?

var dayscollection = new dayscollection([], { url: 'http://api.wunderground.com/api/94c558eeb4e503dc/forecast/q/ca/san_francisco.json' }); dayscollection.fetch({ success: function (collection, response, options) { console.log(collection, response); }, error: function (collection, response, options) { console.log('error'); } });

let me know if need provide more details.

backbone doesn't add together url or urlroot options, models or collections. changelog 1.1.0:

backbone views no longer automatically attach options passed constructor this.options , backbone models no longer attach url , urlroot options, can if prefer.

although doesn't specific collections , if @ code diff between (1.0.0 , 1.1.2) see next line has been removed backbone.collection constructor:

if (options.url) this.url = options.url;

there couple of solutions, first set url afterwards:

var dayscollection = new dayscollection([], {}); dayscollection.url = 'http://api.wunderground.com/api/94c558eeb4e503dc/forecast/q/ca/san_francisco.json';

or, add together options line initialize function collection:

var dayscollection = backbone.collection.extend({ initialize: function(models, options){ if (options.url) this.url = options.url; } });

javascript backbone.js fetch backbone-collections

No comments:

Post a Comment