【问题标题】:Primefaces extensions timerPrimefaces 扩展计时器
【发布时间】:2018-02-12 09:31:59
【问题描述】:

我正在尝试以如下格式制作 primefaces 扩展倒数计时器:

剩余时间:3天,01:15:22

所以我添加了 pe:timer 组件并设置格式如下:

<pe:timer id="time_remaning" timeout="800" format="DDD [days,] HH:mm:ss" immediate="true"/>

但它没有按预期工作。我越来越: 1 天,00 : 13 : 20

但是超时的“天”部分应该是 0 而不是 1。我的格式化程序有错误吗?我从here 获得了格式器参数,如文档中所述。

或者我需要在这个例子中使用自定义的 formatFunction 还是有办法只使用 formater 来做到这一点?

【问题讨论】:

    标签: primefaces timer momentjs primefaces-extensions


    【解决方案1】:

    我无法使用 formater 使其工作,所以我使用 functionFormater 完成工作。

    这是我的 .xhtml 代码:

    <pe:timer id="time_remaning" timeout="#{myBean.getTimeForTimeoutInSeconds()}" 
        formatFunction="return formatMe(value);" />
    

    以及.js格式功能:

    window.formatMe = function (value) {
        var numDays = Math.floor(value / 86400);
        var numHours = Math.floor((value % 86400) / 3600);
        var numMinutes = Math.floor(((value % 86400) % 3600) / 60);
        var numSeconds = ((value % 86400) % 3600) % 60;
        return numDays + " dni, " + pad(numHours, 2) + " : "
            + pad(numMinutes, 2) + " : " + pad(numSeconds, 2) + " ";
    }
    
    function pad(num, size) {
        var s = num+"";
        while (s.length < size) s = "0" + s;
        return s;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-05
      • 1970-01-01
      • 1970-01-01
      • 2019-01-06
      相关资源
      最近更新 更多