sencha touch - how to use data store in initcomponent function of panel
How to read the json object (result of ajax call) inside initcomponent of panel. I have used the following code
initComponent : function() {
Ext.regModel('allVisit', {
fields: [
{ name: 'visitDate', type: 'date'},
{ name: 'doctorInfo', type: 'string'},
{ name: 'patientId', type: 'string'},
{ name: 'visitType', type: 'string'},
{ name: 'referedBy', type: 'string'},
{ name: 'visitId', type: 'string'},
]
});
var allVisitStore = new Ext.data.Store({
model: 'allVisit',
autoLoad : true,
proxy: {
type: 'ajax',
id: 'allvisit_app_localstore',
url: '/RadMobApp/api',
extraParams:{
action:'test',
queryName:'GET_ALL_test',
retFormat:'XML',
patId: '123',
keyValuePair:'yes'
},
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "T4" tag
record: 'data'
})
}
});
var jsonObj = [];
allVisitStore.load();
allVisitStore.data.each(function() {
jsonObj.push({xtype:"panel", title: this.data['visitDate'] + " (" + this.data['visitType'] + ") " + this.data['doctorInfo'] , html : this.data['patientId'], style : 'padding-bottom:10px;'});
});
this.items = jsonObj;
RadMobApp.views.clinicalPanel.superclass.initComponent.call(this);
}
Data store iteration code(given below) is executed before receiving the ajax request value. I have used setTimeOut function for the following set of code
var jsonObj = [];
allVisitStore.load();
开发者_开发问答 allVisitStore.data.each(function() {
jsonObj.push({xtype:"panel", title: this.data['visitDate'] + " (" + this.data['visitType'] + ") " + this.data['doctorInfo'] , html : this.data['patientId'], style : 'padding-bottom:10px;'});
});
this.items = jsonObj;
RadMobApp.views.clinicalPanel.superclass.initComponent.call(this);
but no use, I am getting the issue.
Use the load function like this which will make sure that it executes after the store is loaded!
activityStore.load(function(records, operation, success) {
console.log('num of activities loaded: ' + activityStore.data.length);
});
精彩评论