Skip to content

Instantly share code, notes, and snippets.

@MeoMix
Created April 30, 2013 19:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MeoMix/6ee36e30ea0e9c140ee3 to your computer and use it in GitHub Desktop.
Save MeoMix/6ee36e30ea0e9c140ee3 to your computer and use it in GitHub Desktop.
// Convert data which is sent from the server back to a proper Backbone.Model.
// Need to recreate submodels as Backbone.Models else they will just be regular Objects.
parse: function (data) {
if (data.items.length > 0) {
// Reset will load the server's response into items as a Backbone.Collection
this.get('items').reset(data.items);
} else {
this.set('items', new PlaylistItems());
}
// Remove so parse doesn't set and overwrite instance after parse returns.
delete data.items;
return data;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment