4 ms·
Happy to oblige. There's no built-in convention for it, but you can do something like this: parse: function(attrs) { this.friends = new PeopleCollect
by jashkenas 13y ago
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.
- danabramov 13y agoJeremy, 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 https://gist.github.com/gaearon/6689379