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

How to access the value of a variable outside the callback and load function in store.load?

我正在使用 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

希望对您有所帮助!