[英]extjs setLoading() not working from controller
I have a gridview with a button in it. 我有一个带有按钮的gridview。 When the button is clicked, it calls a method from the controller.
单击该按钮时,它将从控制器调用一个方法。 In that method, I'm trying to show a loading screen, then do some things, then hide the loading screen.
在这种方法中,我试图显示一个加载屏幕,然后做一些事情,然后隐藏该加载屏幕。 Like so:
像这样:
Ext.getCmp('center-panel').setLoading(true);
// do something that takes a couple seconds
Ext.getCmp('center-panel').setLoading(false);
But the setLoading(true) does not kick in until after the method has finished running. 但是setLoading(true)直到方法完成运行后才起作用。 If I comment out the setLoading(false), the loading screen will show itself, just not until after the 2 seconds, and then never go away.
如果我注释掉setLoading(false),则加载屏幕将显示自身,直到2秒之后,然后再也不会消失。
Anybody know if this is possible or I'm doing something fundamentally wrong? 有人知道这是否可能,或者我在做根本上错误的事情吗? The center-panel is defined in my Viewport like this:
中心面板在我的视口中的定义如下:
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);
}
});
Thanks! 谢谢!
gotta use a '#' for ids:
必须为ID使用“#”:
Ext.getCmp('#center-panel').setLoading(true);
Anyways, you don't want to call setLoading(false) right after your "something that takes a couple seconds", as it will get fired too soon. 无论如何,您都不希望在“需要花费几秒钟的时间”之后立即调用setLoading(false),因为它将很快被触发。
You want to pass a callback function into whatever takes a few seconds and then call setLoading(false) from there. 您想将回调函数传递给需要花费几秒钟的时间,然后从那里调用setLoading(false)。
Example: 例:
somePanel.setLoading(true);
someStore.load({
callback:function(){
somePanel.setLoading(false);
}
});
I had the same problem and solved it by calling the setLoading(true) in a 'beforeload' listener of the store and the setLoading(false) in a load callback. 我遇到了同样的问题,并通过在商店的“ beforeload”侦听器中调用setLoading(true)和在加载回调中调用setLoading(false)来解决此问题。 That works perfectly.
那很好。
Here is an example from a view controller's perspective: 从视图控制器的角度来看,这是一个示例:
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);
}
You need show the panel/whatever before loading will work. 您需要先显示面板/任何内容,然后才能加载。 Eg:
例如:
var pnl = Ext.create('my.WhateverPanel');
pnl.show();
pnl.setLoading(true);
setTimeout(function (){
pnl.setLoading(false);
}
,3000);
So I couldn't find a perfect solution, but what I found out was a good workaround was 所以我找不到完美的解决方案,但是我发现一个不错的解决方法是
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('Loading module...'); this.getView()。setLoading('正在加载模块...');
setTimeout(function () { setTimeout(function(){
//process what you want to do next. //处理接下来要做什么。 For example: me.setCurrentView(id);
例如:me.setCurrentView(id);
} , 1); },1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.