Created
November 17, 2012 02:31
-
-
Save zachmayberry/4092782 to your computer and use it in GitHub Desktop.
Serialize form data and reduce to model object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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