Sencha touch -如何在面板的initcomponent函数中使用数据存储

sencha touch - how to use data store in initcomponent function of panel

本文关键字:函数 initcomponent 存储 数据 touch Sencha      更新时间:2023-09-26

如何在面板的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);

但是没有用,我明白了。

像这样使用load函数,这将确保它在存储被加载后执行!

activityStore.load(function(records, operation, success) {
    console.log('num of activities loaded: ' + activityStore.data.length);
});