Created
July 12, 2018 12:23
-
-
Save codecats/89068743dbc5c5141fc3f7ecf34b4a43 to your computer and use it in GitHub Desktop.
Convert js object to DRF nested ( {key1: {key2: value}} => key1.key2: value )
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
//let formData = new FormData() | |
//nested object {key1: {key2: value}} => key1.key2: value | |
_buildDotObject(formData, obj, stack) { | |
for (let property in obj) { | |
if (obj.hasOwnProperty(property)) { | |
if (typeof obj[property] === "object") { | |
this._buildDotObject(formData, obj[property], stack ? (stack + '.' + property): property); | |
} else { | |
formData.append(stack + '.' + property, obj[property]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment