PDA

View Full Version : Load model with JSon params



Cp_Barbossa
26 Sep 2012, 5:49 AM
Hello.

Is there any way to load Model or Store with JSon parameters?

instead of:

MyModel.load(
100, // id to load
{
success: function (result) {
... // some code
}
}
);

to have like this:

MyModel.load(
{
x: 1,
y: 'some param',
obj: {
a: 12,
b: true,
otherObj: {
m: true,
n: 'ok'
}
}
}, // json parameters to load

{
success: function (result) {
... // some code
}
}
);

And same about the store

loiane
26 Sep 2012, 8:37 AM
You can use the config extraParams in the proxy inside a store/model:



Ext.define('MyApp.store.MyJsonStore', {
extend: 'Ext.data.Store',


requires: [
'MyApp.model.MyModel'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'MyJsonStore',
model: 'MyApp.model.MyModel',
proxy: {
type: 'ajax',
extraParams: {
x: 1,
y: 'some param',
obj: {
a: 12,
b: true,
otherObj: {
m: true,
n: 'ok'
}
}
},
reader: {
type: 'json'
}
}
}, cfg)]);
}
});