Created
September 2, 2009 18:23
-
-
Save blowery/179877 to your computer and use it in GitHub Desktop.
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
dojo.objectToQuery = function(/*Object*/ map){ | |
// summary: | |
// takes a name/value mapping object and returns a string representing | |
// a URL-encoded version of that object. | |
// example: | |
// this object: | |
// | |
// | { | |
// | blah: "blah", | |
// | multi: [ | |
// | "thud", | |
// | "thonk" | |
// | ] | |
// | }; | |
// | |
// yields the following query string: | |
// | |
// | "blah=blah&multi=thud&multi=thonk" | |
// FIXME: need to implement encodeAscii!! | |
var enc = encodeURIComponent; | |
var pairs = []; | |
var backstop = {}; | |
for(var name in map){ | |
var value = map[name]; | |
if(value != backstop[name]){ | |
var assign = enc(name) + "="; | |
if(_d.isArray(value)){ | |
for(var i=0; i < value.length; i++){ | |
pairs.push(assign + enc(value[i])); | |
} | |
}else{ | |
pairs.push(assign + enc(value)); | |
} | |
} | |
} | |
return pairs.sort().join("&"); // String | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment