Skip to content

Comment on Backbone.js 1.1 is outparent

Comments

Happy to oblige. There's no built-in convention for it, but you can do something like this:

    parse: function(attrs) {
      this.friends = new PeopleCollection(attrs.friends);
      delete attrs.friends;
      return attrs;
    }
... assuming that friends is an array of JSON objects suitable to be transformed into Person models.

Jeremy, thanks! I tried overriding Model's `parse` in 1.0 but wasn't satisfied because it seems to be called in some cases but not the others. (I can't recall a specific example right now; maybe it was parsing the collection from server, or creating a collection using constructor).

Do you think there are drawbacks to overriding `set`? It seems to work well for me but I'd love to hear your opinion:

https://gist.github.com/gaearon/6689379

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.