我设置了一个消息框来显示当前时间。计时器间隔设置为1000,有2个按钮可启动和停止“计时器”。当单击“停止”按钮时,它会调用Ext.TaskManager.stop方法并将消息框中的文本更新为“已暂停”。然而,当单击“停止”按钮时,文本变为“已暂停”一秒钟,它又变回显示当前时间。当我尝试使用Ext.TaskManager.stopAll();而不是Ext.TaskManager.stop(task)时,它起作用了!为什么?我的代码如下:
<script type="text/javascript">
Ext.onReady (function(){
var config={
msg:'Display Time',
modal:true,
buttons:Ext.Msg.OKCANCEL,
fn:displayTime
}
Ext.MessageBox.msgButtons[0].setText('Start');
Ext.MessageBox.msgButtons[3].setText('Stop');
Ext.MessageBox.show(config);
function displayTime(id){
if(id=='ok'){
var task = {
run:function(){Ext.MessageBox.updateText ('????:' + Ext.util.Format.date(new Date(), 'Y-m-d g:1:s A'));},
interval:1000
}
Ext.TaskManager.start(task);
}
else {
Ext.MessageBox.updateText('Paused!');
Ext.TaskManager.stop(task);
}
};
});
发布于 2012-04-19 10:32:40
该任务是在if中定义的,因此当命中else时,它实际上是在运行Ext.TaskManager.stop(),它不会停止您的任务。将任务移到函数声明之外。
var task = {
run: function () {
Ext.MessageBox.updateText('????:' + Ext.util.Format.date(new Date(), 'Y-m-d g:1:s A'));
},
interval: 1000
}
function displayTime(id) {
if (id == 'ok') {
Ext.TaskManager.start(task);
} else {
Ext.MessageBox.updateText('Paused!');
Ext.TaskManager.stop(task);
}
};https://stackoverflow.com/questions/10220818
复制相似问题