Skip to content

Instantly share code, notes, and snippets.

Last active Dec 29, 2015
What would you like to do?
Name: <input type="text" name="name"/>
Age: <input type="text" name="age"/>
<input type="submit" value="Submit"></input>
var UserForm = Backbone.View.extend({
events: {'submit': 'save'},
initialize: function() {
_.bindAll(this, 'save');
save: function() {
var arr = this.$el.serializeArray();
// This accumulates the name/value hashes into a single hash which is much easier to submit to forms
var data = _(arr).reduce(function(acc, field) {
acc[] = field.value;
return acc;
}, {});;
return false;
var userForm = new UserForm({el: this.$('form'), model: new User()});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment