PDA

View Full Version : How to pass data to store



arandlett
28 Dec 2011, 11:21 AM
I have a list view that calls a store for the list data. I am trying to pass data to the store for filtering or a different url for the proxy how would I accomplish this?

List View:

Ext.define('MonkTouch.view.List', {
extend : 'Ext.List',
xtype : 'mtouch-list',

storeId:null,
constructor : function(config) {
this.setItemTpl(config.template);
Ext.apply(config, {
store : Ext.create('MonkTouch.store.Media')
});
this.callParent([config]);
}
});


Store:

Ext.define('MonkTouch.store.Media',{
extend: 'Ext.data.Store',
model: 'MonkTouch.model.Media',

autoLoad: true,
proxy:{
type:'ajax',
url:'/lib/mk-modules/media.php',
reader:{
type:'json',
root:'items'
}
},
remoteFilter:true,
filters:[]
});

mitchellsimoens
28 Dec 2011, 11:43 AM
If you want to change the url, I would add a little logic to the store definition you made.


Ext.define('MonkTouch.store.Media', {
extend: 'Ext.data.Store',
model: 'MonkTouch.model.Media',

autoLoad: true,
remoteFilter:true,
filters:[],

constructor: function(config) {
config.proxy = {
type : 'ajax',
url : config.url,
reader : {
type : 'json',
root : 'items'
}
};

delete config.url;

this.callParent(config);
}
});

Now you should be able to create a store like:


Ext.create('MonkTouch.store.Media', {
url : '/lib/mk-modules/media.php'
});

arandlett
28 Dec 2011, 12:57 PM
why did you do config.proxy instead of this.proxy?

arandlett
28 Dec 2011, 1:16 PM
Everytime I try to set config.proxy as you have above I get a JS error. The error just says "Error:".