PDA

View Full Version : Howto pass extraParams from view to proxy



P4G0
13 Apr 2012, 1:01 AM
Hey guys,

I want to pass parameters from the view's sourcecode to my store's proxy without using the init function or something like that. This is my view:

Ext.define('App.view.QSPanel', {

extend: 'Ext.tab.Panel',

items: [{
title: 'Basic',
xtype: 'ParameterDiffTable',
store: Ext.create('App.store.QAParameters')
}, {
title: 'Another Tab',
xtype: 'ParameterDiffTable',
store: Ext.create('App.store.QAParameters')
}]

});

And that is my store:

Ext.define('App.store.QAParameters', {

extend : 'Ext.data.Store',


model : 'App.model.QAParameter',


autoLoad : true,


proxy : {
type : 'ajax',
url : BASE_URL + '/getParameters.json',
reader : {
type : 'json'
},
extraParams : {
section : 'basic'
}
}

});

Now I want to display different data depending on the selected tab. Currently I have hardcoded the section 'basic' to my store's proxy (for testing purposes → works), but that should be dynamic. I wonder if it's possible, to pass that parameter like this:


Ext.create('App.store.QAParameters', section: 'xyz');

Any suggestions?

tvanzoelen
13 Apr 2012, 1:49 AM
If you use this Ext.create('App.store.QAParameters', section: 'xyz');

then you can also setup the proxy in the initComponent or else set a constructor in your App.store.QAParameters class



initComponent: function() {

this.proxy = {
type : 'ajax',
url : BASE_URL + '/getParameters.json',
reader : {
type : 'json'
},
extraParams : {
section : this.section
}
};
this.callParent();
}

P4G0
15 Apr 2012, 10:17 PM
Hi tvanzoelen,

thanks for your quick response.

initComponent doesn't work, because Ext.data.Store is no renderable component: look here (http://www.sencha.com/forum/showthread.php?41629-Bug-initComponent-does-not-fire-when-extending-Store)
I tried to declare a constructor for my purpose, but I cannot get it running as it should... could you paste a constructor example?

Regards
Patrick

tvanzoelen
15 Apr 2012, 11:09 PM
Yes you are right.



constructor: function(config) {
var me = this;

config = Ext.apply({}, config);

me.callParent([config]);

}

P4G0
16 Apr 2012, 12:00 AM
Thanks vietits and tvanzoelen, that works =D>

View:

store: Ext.create('App.store.QAParameters', {section: 'basis'})

Store:

Ext.define('App.store.QAParameters', {

extend : 'Ext.data.Store',

model : 'App.model.QAParameter',

autoLoad: true,

constructor: function(config) {
Ext.apply(this, {
proxy: {
type: 'ajax',
url: BASE_URL + '/getParameters.json',
reader: {
type: 'json'
},
extraParams: {
section: config.section
}
}
});
this.callParent();
}

});

vietits
16 Apr 2012, 12:00 AM
If you just want to pass extra params to your proxy, then you could define your store as below


Ext.define('App.store.QAParameters', {
extend : 'Ext.data.Store',
model : 'App.model.QAParameter',
autoLoad : true,
constructor: function(extraParams){
var me = this;


Ext.apply(me, {
proxy : {
type : 'ajax',
url : BASE_URL + '/getParameters.json',
reader : {
type : 'json'
},
extraParams: extraParams
}
});
me.callParent();
}
});

To create a store


var store = Ext.create('App.store.QAParameters', {section: 'basic'});