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

时间:2011-10-10 14:55:06

标签: javascript ajax sencha-touch iteration store

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

但没有用,我遇到了问题。

1 个答案:

答案 0 :(得分:0)

使用这样的加载函数,确保在加载商店后执行它!

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