1. #1
    Sencha User
    Join Date
    Oct 2009
    Posts
    5
    Vote Rating
    0
    bcd is on a distinguished road

      0  

    Default Ext.urlEncode with nested objects/arrays support

    Ext.urlEncode with nested objects/arrays support


    I've made a new urlEncode function which can handle nested objects

    Example:
    Code:
    {
    	a:{
    		b: [1,2,3,4],
    		c: 5
    	},
    	d:{
    		e: {
    			f:6
    		}
    	},
    	g:7,
    	h:[8,9,10]
    }
    will encode to: a[b][]=1&a[b][]=2&a[b][]=3&a[b][]=4&a[c]=5&d[e][f]=6&g=7&h[]=8&h[]=9&h[]=10
    The code:
    Code:
    Ext.urlEncode = function(o, pre, parentKey){
        var buf = [];
    	if(Ext.type(o)=='array'){
    		for(i=0;i<o.length;i++) {
    			val = o[i];
    			if(Ext.type(val)=='array' || Ext.type(val)=='object') {
    				buf = buf.concat(Ext.urlEncode(val, '', (Ext.isDefined(parentKey) ? parentKey : "")+'[]'));
    			} else {
    				buf[buf.length] = {key:(Ext.isDefined(parentKey) ? parentKey+'[]' : i.toString()), value:val};
    			}
    		}
    	}
    	if(Ext.type(o)=='object'){
    		for(key in o) {
    			val = o[key];
    			if(Ext.type(val)=='array' || Ext.type(val)=='object') {
    				buf = buf.concat(Ext.urlEncode(val, '', (Ext.isDefined(parentKey) ? parentKey+'['+key+']' : key)));
    			} else {
    				buf[buf.length] = {key:(Ext.isDefined(parentKey) ? parentKey+'['+key+']' : key), value:val};
    			}
    		}
    	}
    	if(Ext.isDefined(parentKey)) {
    		return buf;
    	} else {
    		return (Ext.isEmpty(pre)?"":pre+"&") + buf.map(function(x){return (x.key)+'='+encodeURIComponent(x.value.toString());}).join('&');
    	}
    };

  2. #2
    Sencha User
    Join Date
    Oct 2007
    Location
    Iran
    Posts
    159
    Vote Rating
    0
    vahid4134 is on a distinguished road

      0  

    Default


    I wrote this
    http://www.extjs.com/forum/showthread.php?t=85170
    but forum moderator move my Thread to help. I dont know why!!!
    No honor is like knowledge

  3. #3
    Ext User
    Join Date
    Dec 2009
    Posts
    2
    Vote Rating
    0
    davitz38 is on a distinguished road

      0  

    Default


    Hi guys,
    I use this url encoder online tool to make sure I'm encoding the right way
    David

  4. #4
    Sencha User
    Join Date
    Oct 2007
    Location
    Iran
    Posts
    159
    Vote Rating
    0
    vahid4134 is on a distinguished road

      0  

    Default


    This method change array or object to url
    No honor is like knowledge

  5. #5
    Sencha - Community Support Team mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,236
    Vote Rating
    5
    mystix will become famous soon enough

      0  

    Default


    Quote Originally Posted by vahid4134 View Post
    I wrote this
    http://www.extjs.com/forum/showthread.php?t=85170
    but forum moderator move my Thread to help. I dont know why!!!
    i moved it back from Help from Extensions.

    i thought it was a question. my bad.

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi