Skip to content

Instantly share code, notes, and snippets.

@zachmayberry
Created November 17, 2012 02:31
Show Gist options
  • Save zachmayberry/4092782 to your computer and use it in GitHub Desktop.
Save zachmayberry/4092782 to your computer and use it in GitHub Desktop.
Serialize form data and reduce to model object
// Serialize form data and reduce to model object
var form = this.$el.find('form').serializeArray();
var data = _(form).reduce(function( acc, field ) {
acc[field.name] = field.value;
return acc;
}, {});
// Save the result
this.collection.create(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment