Created
December 8, 2012 10:51
-
-
Save jonmaim/4239779 to your computer and use it in GitHub Desktop.
Generate query string for angular.js
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
/* Converts an object into a key/value par with an optional prefix. Used for converting objects to a query string */ | |
var qs = function(obj, prefix){ | |
var str = []; | |
for (var p in obj) { | |
var k = prefix ? prefix + "[" + p + "]" : p, | |
v = obj[k]; | |
str.push(angular.isObject(v) ? qs(v, k) : (k) + "=" + encodeURIComponent(v)); | |
} | |
return str.join("&"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/jaf0/e919cc780848811ec480
6: v = obj[p]