0
如何在面板的initcomponent中讀取json對象(ajax調用的結果)。我已經使用了以下代碼sencha touch - 如何在面板的initcomponent函數中使用數據存儲
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);
}
數據存儲迭代代碼(在下面給出)在接收到ajax請求值之前執行。我已經使用setTimeOut函數爲下面的代碼集
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);
但沒有用,我得到的問題。