Extjs 如何访问store.load中回调和加载函数外部的变量值?

Extjs 如何访问store.load中回调和加载函数外部的变量值?,extjs,extjs4,Extjs,Extjs4,我正在使用store.load编写一些代码。这是我的例子 store.load({ callback: function(records, operation, success) { if(success){ var id = store.getAt(0).data.id; } }); 是否有方法访问store.load之外的records.length? 比如,像这样的事情 store.load({ callback: f

我正在使用store.load编写一些代码。这是我的例子

store.load({
callback: function(records, operation, success) {
    if(success){
            var id = store.getAt(0).data.id;
               }
    });
是否有方法访问store.load之外的records.length? 比如,像这样的事情

store.load({
callback: function(records, operation, success) {
    var id = store.getAt(0).data.id;
 console.log(id); //returns the right value, but cannot use this value outside the load. 
}
});
console.log(id);//returns undefined. 
是的,你能做到

//Get the store 
var store = Ext.getStore("STORE_NAME")
//now get the data response set in the store
var myDataResponse = store.proxy.reader.rawData
//myDataResponse is the full set of records in the store

希望有帮助

你的意思是
store.count()
?@digiizmo很抱歉,我使用了错误的变量。我更新了代码。我的意思是在查询并获取数据后从存储中检索数据。所以在我的例子中,我想得到id值。但是,
记录
是一个集合,虽然正确,但您是根据什么标准隔离单个记录的?API有几种从存储中检索数据的方法,如
getRange
find
findBy
等。我再次更新了代码。我也在努力。无论如何。。我知道store.load是异步的,所以在加载完成之前不会设置id的值,因此我得到的id值是未定义的。但是有没有一种方法可以获得价值,函数之外?我认为您试图在同一上下文中完成太多任务-听起来,任何依赖于数据更改的功能都应该在存储上注册一个
侦听器
,以便它能够以类似的异步方式独立响应您的回调。如果是这样,请接受并投票支持我的答案你在找什么!我收到一个错误,说存储未定义。getStore无法获取存储。还有什么我需要添加的吗?在需要存储中的值的位置有存储实例吗。