如何等到所有商店都装载在ExtJs中? [英] How to wait until all stores are loaded in ExtJs?

查看:76
本文介绍了如何等到所有商店都装载在ExtJs中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组由五个商店驱动的组合框,一旦所有商店完全加载,我想启动一个功能。推荐的方法是什么?我可以做这样的事情,但感觉到kludgy:

  var store1Loaded = false; 
var store2Loaded = false;

store1.on('load',function(){
store1Loaded = true;
});

store2.on('load',function(){
store1Loaded = true;
});


store1.load();
store2.load();

函数WaitForFunction()
{
if(!store1Loaded ||!store2Loaded)){
setTimeout(WaitForFunction,100);
返回;
}
AllStoresLoaded();
}

函数AllStoresLoaded(){
//做某事
}

$使用 store.isLoading() 方法,我认为这是什么。我使用它,它工作正常。


  1. 在执行
    之前配置要加载的商店,一些 storeId config。


  2. 将这些 storeIds p>


  3. 每当这些商店中的一个加载遍历数组时,使用 Ext.getStore 查找商店并调用


  4. 如果数组中的任何一个存储都仍在加载,请执行您的逻辑


例如,说我想要 store1 code> store2 在执行一些逻辑之前加载(我在非MVC模式中显示这个,因为看起来你没有使用你的代码段中的MVC模式)。

  var store1 = Ext.create('Ext.data.Store',{
model:myModel,
storeId:'store1 ',//存储需要完成MVC样式或者具有这个配置
proxy:{
type:'ajax',
url:'url ... ',
reader:'json'
},
autoLoad:{
callback:initData //在加载
时执行此功能
}) ;

var store2 = Ext.create('Ext.data.Store',{
model:myModel,
storeId:'store2',
proxy:{
类型:'ajax',
url:'url ...',
reader:'json'
},
autoLoad:{
callback: initData //在加载
}
}时执行此功能;

//要检查的商店
var myComboStores = ['store1','store2']

//如果它们都完成加载,则函数执行逻辑
函数initData(){
var loaded = true;
Ext.each(myComboStores,function(storeId){
var store = Ext.getStore(storeId);
if(store.isLoading()){
loaded = false;
}
});
if(loaded){
// do data with the data
}
}


I have a set of combo boxes that are driven by five stores and I want to fire a function once all the stores are completely loaded. What is the recommended way of doing this? I could do something like this but it feels kludgy:

var store1Loaded = false;
var store2Loaded = false;

store1.on('load', function(){
    store1Loaded = true;
});

store2.on('load', function(){
    store1Loaded = true;
});


store1.load();
store2.load();

function WaitForFunction()
{
    if (!store1Loaded || !store2Loaded)) {
       setTimeout( WaitForFunction, 100);
       return;
    }
    AllStoresLoaded();
}

function AllStoresLoaded(){
      //Do Something
}

解决方案

Use the store.isLoading() method, I think that is what it is for. I use it and it works fine.

  1. Configure the stores that you want to be loaded before performing some logic with a storeId config.

  2. Put these storeIds into an array.

  3. Whenever one of these stores is loaded iterate through the array, lookup the store with Ext.getStore and call isLoading on it.

  4. If none of the stores in the array are still loading, perform your logic.

For example, say I want store1 and store2 loaded before I perform some logic (I am showing this in non-MVC pattern because it looks like you are not using MVC pattern from your snippet).

var store1 = Ext.create('Ext.data.Store', {
    model: myModel,
    storeId: 'store1', // store needs to be done MVC style or have this config
    proxy: {
        type: 'ajax', 
        url: 'url...',
        reader: 'json'
    },
    autoLoad: {
        callback: initData // do this function when it loads
    }
});

var store2 = Ext.create('Ext.data.Store', {
    model: myModel,
    storeId: 'store2',
    proxy: {
        type: 'ajax', 
        url: 'url...',
        reader: 'json'
    },
    autoLoad: {
        callback: initData // do this function when it loads
    }
});

// the stores to be checked
var myComboStores = ['store1', 'store2']

// function does logic if they are both finished loading
function initData() {
    var loaded = true;
    Ext.each(myComboStores, function(storeId) {
        var store = Ext.getStore(storeId);
        if (store.isLoading()) {
            loaded = false;
        }
    });
    if(loaded) {
        // do stuff with the data
    }
}

这篇关于如何等到所有商店都装载在ExtJs中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆