Skip to content

Instantly share code, notes, and snippets.

@fourcolors
Created April 9, 2013 20:10
Show Gist options
  • Save fourcolors/5348956 to your computer and use it in GitHub Desktop.
Save fourcolors/5348956 to your computer and use it in GitHub Desktop.
Allow nested attributes on a backbone model
# Example usage
# @model.setNestedAttribute parent: 'foo', property: 'bar', value: 'catz', silent: true
setNestedAttribute: (options) ->
parent = options.parent
value = options.value
property = options.property
silent = options.silent
date_data = @get(parent) || {}
date_data[property] = value
@set(parent, date_data, {silent: silent})
console.log date_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment