Last active
August 29, 2015 14:05
-
-
Save weishai/ca3fca0e701691393dbf to your computer and use it in GitHub Desktop.
serialize Object for Form
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
$.fn.serializeObject = function() { | |
var o = Object.create(null), | |
elementMapper = function(element) { | |
element.name = $.camelCase(element.name); | |
return element; | |
}, | |
appendToResult = function(i, element) { | |
var node = o[element.name]; | |
if ('undefined' != typeof node && node !== null) { | |
o[element.name] = node.push ? node.push(element.value) : [node, element.value]; | |
} else { | |
o[element.name] = element.value; | |
} | |
}; | |
$.each($.map(this.serializeArray(), elementMapper), appendToResult); | |
return o; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment