Skip to content

Instantly share code, notes, and snippets.

@CoralineAda
Created March 3, 2013 16:14
Show Gist options
  • Save CoralineAda/5076709 to your computer and use it in GitHub Desktop.
Save CoralineAda/5076709 to your computer and use it in GitHub Desktop.
Save only certain attributes in a Backbone model
MyApp.Foo = Backbone.Model.extend(
urlRoot: '/foos'
defaults:
attrs_to_sync: ['name', 'points']
toJSON: (options) ->
attr = _.clone(@attributes)
json = new Object
_(@get('attrs_to_sync')).each (k) ->
json[k] = attr[k]
json
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment