【发布时间】:2011-10-10 14:55:05
【问题描述】:
如何在面板的 initcomponent 中读取 json 对象(ajax 调用的结果)。我使用了以下代码
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);
但没用,我遇到了问题。
【问题讨论】:
标签: javascript ajax sencha-touch iteration store