Primefaces 一项民意调查 "pause" 另一项民意调查

Primefaces one poll "pause" another poll

我在同一个页面上有两个 primefaces 投票。

其中一个(pollLg)的间隔时间较长(30秒),而另一个(pollSm)的间隔时间较短(8秒)。

pollLg开始时,我希望pollSm到"pause"然后在pollLg完成任务后继续(记住它被打断的时间)。

如果我在pollLg任务中调用PF('pollSm').stop()PF('pollSm').start()pollSm只会在8秒后再次执行。

例如,当网页打开时,我有:

pollSm executions: 8sec, 16sec, 24sec (pollLg will execute here and stop pollSm)

pollLg完成后,pollSm只会在8秒后执行,而不是2秒(被6秒中断)

有什么简单的方法可以做到这一点吗?

首先让我声明 PrimeFaces 源代码是开放的,可以轻松用于检查(可能未记录)功能。我做了并注意到您不能在 PrimeFaces 中轻松地做到这一点,因为它的轮询组件具有内置功能。在 javascipt source of the component 中,您可以看到它使用普通的 javascript 计时器。

所以我开始搜索是否可以简单地做到这一点 javascript 并注意到那里也没有简单的功能。幸运的是,Whosebug 中已经存在关于 pausing/resuming a timer in javascript and it even has an answer that is about repeating timers 的 Q/A。

如果你把这个和结合起来,你就可以达到你想要的效果。