错误存储加载

时间:2012-05-03 22:00:28

标签: sencha-touch extjs store sencha-touch-2

晚上好。

我的应用程序的初始视图需要从Store(autoLoad = true)获取一些数据来更改它的某些组件。我能在什么时候做到这一点?

查看:

    Ext.define('App.view.EmpresaPanel', {
    extend: 'Ext.Container',
    alias: 'widget.empresapanel',

    config: {
        ui: 'dark',
        layout: {
            type: 'card'
        },
        items: [
            {
                xtype: 'titlebar',
                docked: 'top',
                title: 'Menu',
                layout: {
                    align: 'center',
                    type: 'hbox'
                }
            },
            {
                xtype: 'titlebar',
                docked: 'bottom',
                title: '2012 ©',
                layout: {
                    align: 'center',
                    type: 'hbox'
                }
            }       
        ]
    }

});

商店:

Ext.define('App.store.Empresa', {
    extend: 'Ext.data.Store',
    requires: [
        'App.model.Empresa'
    ],

    config: {
        autoLoad: true,
        autoSync: true,
        model: 'App.model.Empresa',
        storeId: 'EmpresaStore',
        proxy: {
            type: 'ajax',
            url: 'http://URL',
            reader: {
                type: 'json',
                rootProperty: 'empresa'
            }
        }
    }
});

控制器:

Ext.define('App.controller.Empresa', {
    extend: 'Ext.app.Controller',
    config: {
        refs: {
            empresaPanel: 'empresapanel'
        },

        control: {
            "empresapanel": {
                initialize: 'onContainerInitialize'
            }
        }
    },

    onContainerInitialize: function(component, options) {
        var store = Ext.getStore("EmpresaStore"),
        record = store.findRecord("id", "1");

        console.log(store);
        console.log(record);

    }

});

首先出现在console.log中:Ext.apply.create.Class 在第二个:null

如果我在此视图中放置一个按钮并点击相同的事件,则运行与“onContainerInitialize”函数相同的代码,记录已完成。

创建视图后是否有特定时间可以从商店访问数据?

谢谢!

1 个答案:

答案 0 :(得分:1)

您应该为store load event添加侦听器以从商店访问记录。 这是一个如何做到这一点的例子。将以下代码放在onContainerInitialize:

store.on('load', function(t) {
    var record = t.findRecord("id", "1");
    console.log(record);
}, this, {single: true});