Skip to content

Instantly share code, notes, and snippets.

@andrewdeandrade
Created April 10, 2011 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewdeandrade/912580 to your computer and use it in GitHub Desktop.
Save andrewdeandrade/912580 to your computer and use it in GitHub Desktop.
// My controller:
pg.controllers.Main = Backbone.Controller.extend({
routes: { },
initialize: function () {
pg.account = new pg.model.Account(window.account);
Users = new pg.collections.UserList({ url: "/profiles" });
Backbone.history.start();
}
});
// My UserList constructor:
pg.collections.UserList = Backbone.Collection.extend({
model: pg.model.User,
initialize: function(options) {
this.options = options || {};
if (this.options.url) this.url = this.options.url;
}
});
// The above doesn't work because the api for Collections (and Models) is different than for Views.
// This inconsistency led to a bug where Backbone.Collection was taking my options, { url: "/profiles" } and treating it as the 'models' arg.
// I finally figured out that I need to do this instead:
// My controller:
pg.controllers.Main = Backbone.Controller.extend({
routes: { },
initialize: function () {
pg.account = new pg.model.Account(window.account);
Users = new pg.collections.UserList(null, { url: "/profiles" });
Backbone.history.start();
}
});
// My UserList constructor:
pg.collections.UserList = Backbone.Collection.extend({
model: pg.model.User,
initialize: function(models, options) {
this.options = options || {};
if (this.options.url) this.url = this.options.url;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment