Created
April 10, 2011 18:10
-
-
Save andrewdeandrade/912580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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