PDA

View Full Version : Control parameters from JSON writer



stoertebeker
8 Jul 2012, 5:20 AM
Hi,
how can I control the parameters that are sent from a JSON writer? Especially the unwanted one.
Here is the store, model and proxy.

Ext.define('MyApp.store.MyStore', { extend: 'Ext.data.Store',
requires: [
'MyApp.model.MyModel'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'MyStore',
model: 'MyApp.model.MyModel',
data: [
{
id: 'a',
f2: 'b',
f3: 'c'
},
{
id: 'a1',
f2: 'b1',
f3: 'c1'
}
]
}, cfg)]);
}
});
Ext.define('MyApp.model.MyModel', {
extend: 'Ext.data.Model',


idProperty: 'xx',


fields: [
{
name: 'id'
},
{
name: 'f2'
},
{
name: 'f3'
}
],


proxy: {
type: 'jsonp',
url: 'checkout.php',
autoAppendParams: false,
reader: {
type: 'json',
root: 'rows'
},
writer: {
type: 'json',
encode: true,
root: 'rows'
}
}
});
The parameters that are sent with the request are as follows.

dc:
1341750115408
records:
id
f2:
b
f3:
c
xx:
id
f2:
b1
f3:
c1
xx:

rows:
[{"id":"a","f2":"b","f3":"c","xx":null},{"id":"a1","f2":"b1","f3":"c1","xx":null}]
callback:
Ext.data.JsonP.callback1

What I do not understand, is how to control the parameters 'records,f2,f3,xx,f2,f3,xx'. They seem to make no sense and what values are assigned!

The values that are assigned to 'rows' I would have expected under 'records'. And it also took me some trial and error to produce the 'rows' parameter. It only shows up when 'autoAppendParams: false' is set on the proxy. Honestly, after reading the documentation a couple of times I do not see a relationship to the show/no-show of the 'rows'.

Another strange behavior is related to the 'idProperty'. When the default is not overwritten, no http-request is sent at all. When I overwrite it with 'xx', the request is sent (but unfortunately not with the expected content).

Thanks for any thought.

skirtle
8 Jul 2012, 7:54 AM
The JsonP proxy has a number of quirks for data writing that were fixed recently but they didn't make it into 4.1.1. Do you definitely need a JsonP proxy rather than just an Ajax proxy?

stoertebeker
25 Jul 2012, 10:27 AM
Hi, I tested the AJAX proxy and then the parameters look clean and 'as expected'. So I might have to to some re-design or wait for the next fix.