如何将msg.payload从注入节点移动到节点红色仪表板中的模板节点?

时间:2018-02-10 06:56:01

标签: javascript node-red

这是节点红色dasboard节点的模板节点,我需要注入格式化为" Feb 09,2001 13:50:05"例如。如果我将取消注释第一个indate var它将起作用。

<div class="login-page">
    <div class="form">
        <form class="login-form" th:action="@{/login}" method="post">
            <input type="text" placeholder="Username" id="username"
                name="username" />
            <input type="password" placeholder="Password" id="password"
                name="password" />
            <button type="submit">login</button>
            <p class="message">
                Not registered?
                <a th:href="@{/reg}">Create an account</a>
            </p>
        </form>
        <label th:if="${param.error}"
            class="message text-danger text-capitalize">Login
            credentials invalid</label>
    </div>
</div>

在我的node-red config中,这2个节点看起来像

<script>
// Set the date we're counting down to
//var countDownDate = new Date({{msg.payload}}).getTime();
//var indate = "Feb 09, 2018 13:50:05";
var indate = msg.payload;
var countDownDate = new Date(indate).getTime();

// Update the count down every 1 second
var x = setInterval(function() {

    // Get todays date and time
    var now = new Date().getTime();

    // Find the distance between now an the count down date
    var distance = countDownDate - now;

    // Time calculations for days, hours, minutes and seconds
    var days = Math.floor(distance / (1000 * 60 * 60 * 24));
    var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = Math.floor((distance % (1000 * 60)) / 1000);

    // Output the result in an element with id="demo"
    document.getElementById("demo").innerHTML = days + "d " + hours + "h "
    + minutes + "m " + seconds + "s ";

    // If the count down is over, write some text 
    if (distance < 0) {
        clearInterval(x);
        document.getElementById("demo").innerHTML = "EXPIRED";
    }
}, 1000);
</script>

1 个答案:

答案 0 :(得分:0)

为什么不在Dashboard Template节点之前使用node-red-contrib-moment?使用它将正确格式化的日期附加到msg,然后在仪表板中使用。

相关问题