PDA

View Full Version : Assigning store to list MVC Pattern



FullThrottle
7 Dec 2011, 6:53 AM
I'm having some trouble assigning a store to a list. I can do it dynamically in the controller, but I can not seem to get the store property of the list itself to work.

Controller:


Ext.define('Test.controller.PatientController', {
extend: 'Ext.app.Controller',


config: {
profile: Ext.os.deviceType.toLowerCase()
},


views: [
'PatientList'
],
stores: [
'PatientStore'
],
models: [
'PatientModel'
],


init: function()
{
Ext.getCmp('patientList').setStore('PatientStore');
}
});


Store:


Ext.define('Test.store.PatientStore', {
extend: 'Ext.data.Store',
model: 'Test.model.PatientModel',
requires: [ 'Test.model.PatientModel' ],
storeId: 'patientStore',
sorters: 'lastName',
getGroupString: function(record){
return record.get('lastName')[0];
},
autoLoad: false,
autoSync: true,


proxy: {
type: 'ajax',
api: {
read: '../Services/PatientWebService.asmx/GetAllPatients'
},
reader: {
type: 'xml',
record: 'PatientData',
root: 'ArrayOfPatientData'
},
afterRequest: function(response, opts){


}
}
});


List:



Ext.define('Test.view.PatientList', {
extend: 'Ext.dataview.List',
xtype: 'patientList',
id: 'patientList',
fullscreen: true,
config: {
itemTpl: '<div id="{id}">{lastName}, {firstName}</div>',
listeners: {
scope: this,
itemtap: this.onItemTap
}
},


onItemTap: function(record, newItem){
if(newItem.attributes['id'] != undefined)
{
Ext.getCmp('mainPanel').setActiveItem(2);
Ext.data.StoreManager.lookup('PatientDateStore').getProxy().extraParams.ID = newItem.attributes['id'].value;
Ext.data.StoreManager.lookup('PatientDateStore').load();
}
else if (newItem.childNodes[0].attributes['id'] != undefined)
{
Ext.getCmp('mainPanel').setActiveItem(2);
Ext.data.StoreManager.lookup('PatientDateStore').getProxy().extraParams.ID = newItem.childNodes[0].attributes['id'].value;
Ext.data.StoreManager.lookup('PatientDateStore').load();
}
else
{
Ext.Msg.alert('Error', 'Patient does not have a valid ID, please try again.')
}
}
});


If I put the storeId in the List's config section the data doesn't load, the only way I've seen data load is by setting it in the controller which I don't really like how that looks.

What I add to the List config section:



store: 'PatientStore'

joejernst
7 Dec 2011, 4:10 PM
I had the same problem. The solution is in this thread: http://www.sencha.com/forum/showthread.php?156195-Can-t-get-Store-to-work-using-MVC-pattern

FullThrottle
7 Dec 2011, 6:08 PM
Awesome, that totally fixed it. I thought including the store in the controller would do what the stores property in the app.js does, but apparently not. Thx