0
嘿傢伙我#m與meteor.js中的模板嘗試,但我怎麼能在給定時間後重新加載它們? ,例如我想要一個名爲「時間」的模板,必須重新加載每一秒以顯示當前時間,還需要每分鐘重新加載一個模板「日期」,因爲每分鐘日期可以更改,或者日曆至極必須每5分鐘左右重新載入一次,以保持準確。Meteor.js中的簡單時鐘或如何重新加載模板?
我當前的代碼看起來像這樣:
<body>
<!-- TOP -->
<div class="top left">{{> time }}</div>
<div class="top mid"></div>
<div class="top right">{{> date }}</div>
</body>
<template name="time">
<div>{{ clock }}</div>
</template>
<template name="date">
<div>{{ date }}</div>
</template>
的JS:
if (Meteor.isClient) {
Template.time.helpers({
clock: function() {
var currentTime = new Date();
var currentHours = currentTime.getHours();
var currentMinutes = currentTime.getMinutes();
var currentSeconds = currentTime.getSeconds();
currentHours = (currentHours < 10 ? "0" : "") + currentHours;
currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;
return currentHours + ":" + currentMinutes + ":" + currentSeconds;
}
});
Tempate.date.helpers({
date: function() {
var month = ["Januar", "Februar", "März", "April", "Mai", "Juni", "July", "August", "September", "October", "November", "Dezember"];
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
return d + " " + month[m] + " " + y;
}
});
}
請幫助我提高我的知識!
-Tim4497
您可能會發現[remcoder:chronos](https://atmospherejs.com/remcoder/chronos)包有幫助。 –