killfill
16 Apr 2011, 8:09 AM
Dont know if this is a bug or a feature request...
But i noticed that
Ext.urlEncode({k1: 1, sub: {subk1: 1, subk2: 2}}) will produce
"k1=1&sub=%5Bobject%20Object%5D".
I need to add some extra data before submitting the form to the server.
I think the most clean way in my case, is to send it as a hash. Maybe is a good idea to make urlEncode produce
"k1=1&sub%5Bsubk1%5D=1&sub%5Bsubk2%5D=2"
i.e. "k1=1&sub[subk1]=1&sub[subk2]=2.
Im using this, wich is working just for for me.
Thanks!
Ext.urlEncode = function(o, pre, keyPrefix){
var empty,
buf = [],
e = encodeURIComponent;
Ext.iterate(o, function(key, item){
empty = Ext.isEmpty(item);
Ext.each(empty ? key : item, function(val){
key = keyPrefix? keyPrefix + '['+key+']' : key;
if (Ext.isObject(item))
buf.push('&',Ext.urlEncode(item, pre, key))
else if (Ext.isArray(item))
item.forEach(function(i) {
buf.push('&', Ext.urlEncode(i, pre, key));
});
else
buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
});
});
if(!pre){
buf.shift();
pre = '';
}
return pre + buf.join('');
};
But i noticed that
Ext.urlEncode({k1: 1, sub: {subk1: 1, subk2: 2}}) will produce
"k1=1&sub=%5Bobject%20Object%5D".
I need to add some extra data before submitting the form to the server.
I think the most clean way in my case, is to send it as a hash. Maybe is a good idea to make urlEncode produce
"k1=1&sub%5Bsubk1%5D=1&sub%5Bsubk2%5D=2"
i.e. "k1=1&sub[subk1]=1&sub[subk2]=2.
Im using this, wich is working just for for me.
Thanks!
Ext.urlEncode = function(o, pre, keyPrefix){
var empty,
buf = [],
e = encodeURIComponent;
Ext.iterate(o, function(key, item){
empty = Ext.isEmpty(item);
Ext.each(empty ? key : item, function(val){
key = keyPrefix? keyPrefix + '['+key+']' : key;
if (Ext.isObject(item))
buf.push('&',Ext.urlEncode(item, pre, key))
else if (Ext.isArray(item))
item.forEach(function(i) {
buf.push('&', Ext.urlEncode(i, pre, key));
});
else
buf.push('&', e(key), '=', (!Ext.isEmpty(val) && (val != key || !empty)) ? (Ext.isDate(val) ? Ext.encode(val).replace(/"/g, '') : e(val)) : '');
});
});
if(!pre){
buf.shift();
pre = '';
}
return pre + buf.join('');
};