I need to pass a urlRoot to a model at runtime, as several different classes of the model use different urlRoots.
Here is my model:
App.Models.Table = Backbone.Model.extend({ });
And here is where I am going to use it:
var m = new App.Models.Table();
var t = new App.Collections.Tables(m, { url: this.url });
var tables = new App.Views.Tables({ collection: t, template: this.template });
this.url returns the correct value, based on the event that calls it. Am I passing my model into the collection wrong? Here is my collection:
App.Collections.Tables = Backbone.Collection.extend({
url: this.url,
model: App.Models.Table,
initialize: function(models, options) {
if (options && options.url) {
this.url = options.url;
}
this.fetch({
success: function(data, options) {
}
});
}
});
How do I pass in this.url to my model?
Assuming
this.urlis the correct url in your example, then do the following: