我正在使用基于日历的仪表板小部件,希望在新的一天开始时自动进行更新。但是,我似乎无法真正进行更新。在浏览器中运行似乎正常。我也尝试过手动将setTimeout延迟输入到更短的时间(例如1或2分钟),这似乎可行。
这是我的代码:
function Calendar() {
var _self = this;
this.daytimer = null;
this.daytimerAction = function() {
_self.updateCurrentDate();
}
this.resetDaytimer();
}
Calendar.prototype.resetDaytimer = function() {
var today = new Date(),
tomorrow = new Date();
if (this.daytimer) {
clearTimeout(this.daytimer);
this.daytimer = null;
}
tomorrow.setDate(today.getDate() + 1);
tomorrow.setHours(0);
tomorrow.setMinutes(0);
tomorrow.setSeconds(1);
this.daytimer = setTimeout(this.daytimerAction, tomorrow.getTime() - today.getTime());
};
Calendar.prototype.updateCurrentDate = function() {
// Run code to update the day display
this.resetDaytimer();
};
有什么想法吗?我唯一能想到的是,当仪表板不运行时,仪表板正在暂停/取消setTimeout。也许有一种方法可以在重新激活仪表板时重置超时?
弄清楚了。Apple文档概述了widget.onshow
可用于重新启动计时器以及updateCurrentDate()
直接调用的事件。还有一个widget.onhide
事件可用于暂停计时器。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句