Grid 从Ext.data.Store外部获取JSON数组?

Grid 从Ext.data.Store外部获取JSON数组?,grid,extjs,Grid,Extjs,如何从函数外部的Ext.data.Store获取JSON数组? 守则: var store = new Ext.data.Store({ model: 'nested' + type, proxy: { type: 'ajax', url: '/Grid/GetDetailed?InvoiceId=' + $(row).attr('id'),

如何从函数外部的Ext.data.Store获取JSON数组? 守则:

var store = new Ext.data.Store({
                model: 'nested' + type,
                proxy: {
                    type: 'ajax',
                    url: '/Grid/GetDetailed?InvoiceId=' + $(row).attr('id'),
                    reader: {
                        type: 'json',
                        root: 'items',
                        totalProperty: 'totalCount'
                    }
                }
            });
            store.load();
我想用这样的东西:

store.getAt(0);
但它还没有定义。 有人说这是使用了异步的ajax。

在创建存储时使用而不是
new
关键字,并为存储定义一个。然后您可以使用方法检索存储。

如果在调用store.load()之后立即使用store.getAt(0),那么是的,问题是加载是异步的,因此您应该使用加载的回调方法来解决此问题

store.load({
    scope   : this,
    callback: function(records, operation, success) {
        //here the store has been loaded so you can use what functions you like
        store.getAt(0);
    }
});

您还可以通过执行以下操作使其正常工作:

//This function will be called only after the store has been loaded successfully.
store.on('load',function(this, records, successful, eOpts){
     store.getAt(0);
}, this);

store
本身是否未定义,或者
getAt(0)
调用是否返回未定义的记录?在后一种情况下,原因可能是@nscrob写的。在尝试访问其内容之前,需要确保存储已加载。