PDA

View Full Version : Nested object with baseParams



fudriot
12 Aug 2010, 12:11 AM
In the frame of an Ajax request, I am trying to use a nested object in "baseParams". Basically, I would like to produce an URL like "ajax.php?foo[controller]=demo&foo[action]=index". I thought about this code which wrongly produces: "ajax.php?foo=[object]&foo=[object]".



var store = new Ext.data.JsonStore(
baseParams: {
foo: {
controller: 'demo',
action: 'index'
}
},
proxy: new Ext.data.HttpProxy({
method: 'GET',
url: '/ajax.php'
}),
(...)
);A quick solution would be to write the code like bellow ...



var store = new Ext.data.JsonStore(
baseParams: {
'foo[controller]': 'demo',
'foo[action]': 'index'
}
},
(...)
);... but then it is not handy to manipulate baseParams as the object contains special characters ("[" and "]"). How can you add / change values dynamically with special character?

store.baseParams.foo[controller] = 'demo2' -> is not valid javascript

Is it a bug or a missing feature?

fudriot
12 Aug 2010, 12:41 AM
I tried also

var result = Ext.urlEncode({
foo : {
controller : 'demo'
}
});with the result: foo=%5Bobject%20Object%5D

fudriot
12 Aug 2010, 12:50 AM
Actually, I found a solution with

store.setBaseParam('foo[controller]': 'demo')

But, it does not explain why nested objects are not encoding correctly in the URL.