【问题标题】:sencha touch - how to use data store in initcomponent function of panelsencha touch - 如何在面板的initcomponent函数中使用数据存储
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多