Skip to content

Instantly share code, notes, and snippets.

@ajacksified
Created May 17, 2012 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ajacksified/2721165 to your computer and use it in GitHub Desktop.
Save ajacksified/2721165 to your computer and use it in GitHub Desktop.
Coffeescript / Underscore form serialization
serializeForm: ($el) ->
return _.reduce($el.serializeArray(), (memo, v) ->
if v.name.match(/\[\]/)
v.name = v.name.replace(/\[\]/,'')
memo[v.name] ?= []
memo[v.name].push(v.value)
else
memo[v.name] = v.value
memo
, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment