beforeLoad 事件超时
我正在尝试编写一些 ExtJS 4 脚本。我有以下代码:
var companyStoreModel = Ext.create('Ext.data.Store', {
model: 'CompanyDataModel',
proxy: {
type: 'ajax',
url: _company_load_url,
reader: 'json',
},
listeners: {
beforeload: function(store, options) {
loadFunction(0);
},
load: function(store, records, options) {
$('section#test').html('test: data loaded');
},
},
autoLoad: true,
});
在脚本的开头我有:
var _timeout;
var loadFunction = function(no)
{
$('section#test').html('test: is loading');
for (var i = 0; i<no; i++)
{
$('section#test').append('.');
}
_timeout = setTimeout(loadFunction(no++), 100);
}
所以我想向用户显示数据正在加载。数据加载良好,一切正常,无需 beforeload
事件。这段代码在
_timeout = setTimeout(loadFunction(no++), 100);
调用时给我 jQuery 错误。错误是:超出最大调用堆栈大小
。有人可以给我提示如何做这样的事情或者我做错了什么吗?
I'm trying to write some ExtJS 4 script. I have the following code:
var companyStoreModel = Ext.create('Ext.data.Store', {
model: 'CompanyDataModel',
proxy: {
type: 'ajax',
url: _company_load_url,
reader: 'json',
},
listeners: {
beforeload: function(store, options) {
loadFunction(0);
},
load: function(store, records, options) {
$('section#test').html('test: data loaded');
},
},
autoLoad: true,
});
and at the begining of the script I have:
var _timeout;
var loadFunction = function(no)
{
$('section#test').html('test: is loading');
for (var i = 0; i<no; i++)
{
$('section#test').append('.');
}
_timeout = setTimeout(loadFunction(no++), 100);
}
So I want to show to the user that data is being loaded. Data is loaded well and everything works without beforeload
event. This code gives me jQuery error when
_timeout = setTimeout(loadFunction(no++), 100);
is called. The error is: Maximum call stack size exceeded
. Can someone give me a hint how to do such thing or what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在,您的函数正在立即执行(导致巨大的执行调用堆栈)。您不能将其放入
setTimeout
函数中。您可以仅传递函数名称(可以评估的代码),也可以使用匿名函数:名称:
Eval:
Anon。功能。
Right now, your function is being executed straight away (causing a huge call stack of executions). You cannot put it in the
setTimeout
function like that. You either pass ONLY the function name, a code that can be eval'd or you use an anonymous function:Name:
Eval:
Anon. func.
加载数据时,您必须
clearTimeout
:You have to
clearTimeout
when data is loaded: