簡體   English   中英

extjs setLoading()無法從控制器工作

[英]extjs setLoading() not working from controller

我有一個帶有按鈕的gridview。 單擊該按鈕時,它將從控制器調用一個方法。 在這種方法中,我試圖顯示一個加載屏幕,然后做一些事情,然后隱藏該加載屏幕。 像這樣:

Ext.getCmp('center-panel').setLoading(true);        
// do something that takes a couple seconds
Ext.getCmp('center-panel').setLoading(false);

但是setLoading(true)直到方法完成運行后才起作用。 如果我注釋掉setLoading(false),則加載屏幕將顯示自身,直到2秒之后,然后再也不會消失。

有人知道這是否可能,或者我在做根本上錯誤的事情嗎? 中心面板在我的視口中的定義如下:

Ext.define('HelperBatchForm.view.Viewport', {
extend: 'Ext.container.Viewport',    
layout: 'fit',
items: [
    {
        region: 'center',
        id: 'center-panel',
        title: 'Batches',
        split: true,
        collapsible: true,
        xtype: 'batchgrid'
    }
    ,
    {
        region: 'south',
        id: 'south-panel',
        title: 'Batch Form',
        split: true, 
        //collapsible: true,            
        xtype: 'batchedit'            
    }
],

initComponent: function () {
    this.callParent(arguments);
}

});

謝謝!

必須為ID使用“#”:

 
 
 
  
  Ext.getCmp('#center-panel').setLoading(true);
 
  

無論如何,您都不希望在“需要花費幾秒鍾的時間”之后立即調用setLoading(false),因為它將很快被觸發。

您想將回調函數傳遞給需要花費幾秒鍾的時間,然后從那里調用setLoading(false)。

例:

somePanel.setLoading(true);

someStore.load({

  callback:function(){

    somePanel.setLoading(false);

  }
}); 

我遇到了同樣的問題,並通過在商店的“ beforeload”偵聽器中調用setLoading(true)和在加載回調中調用setLoading(false)來解決此問題。 那很好。

從視圖控制器的角度來看,這是一個示例:

configureStore: function(store) {
    var me = this;
    store.on('beforeload', me.onStoreBeforeLoad, me);
    store.load({
        callback:function() {
            me.getView().setLoading(false);
        }
    });
},

onBeforeStoreLoad: function(store, operation, eOpts) {
    this.getView().setLoading(true);
}

您需要先顯示面板/任何內容,然后才能加載。 例如:

        var pnl = Ext.create('my.WhateverPanel');
        pnl.show();
        pnl.setLoading(true);
        setTimeout(function (){
            pnl.setLoading(false);
        }
        ,3000);

所以我找不到完美的解決方案,但是我發現一個不錯的解決方法是

Ext.getCmp('center-panel').setLoading(true); 
Ext.Function.defer(function () {
    // do something that takes a couple of seconds in here
    Ext.getCmp('center-panel').setLoading(false);
}, 10);

this.getView()。setLoading('正在加載模塊...');
setTimeout(function(){
//處理接下來要做什么。 例如:me.setCurrentView(id);
},1);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM