Meteor - 解锁模板一段时间(按日期)
Meteor - Unlock template for a certain period of time (by Date)
我只想展示一个问卷模板一段时间。从 5 月 5 日到 5 月 9 日。
我想像一个模板助手,如果 5 月 5 日已经开始,returns 为真,如果 5 月 9 日已经过去,则为假。但是我怎样才能有效地更新 if 语句的瞬时时间值呢?
Template.registerHelper("questionaireUnlocked", function() {
let now = new Date();
let startDate;
let endDate;
if (now > startDate && now < endDate) {
return true;
}
});
感谢您的帮助!
手筒
您可以使用自动运行将时间分配给父模板中的反应变量,例如 Session 变量或 ReactiveVar。
Template.myParentTemplateName.created = function () {
const template = this;
template.autorun(function () {
Meteor.setInterval(Session.set("newTime",new Date()), 6000);
});
}
Template.myParentTemplateName.helpers ({
"questionaireUnlocked" : function () {
const now = Session.get("newTime");
.....
if (now > startDate && now < endDate) {
return true;
}
}
})
希望对您有所帮助。
我只想展示一个问卷模板一段时间。从 5 月 5 日到 5 月 9 日。
我想像一个模板助手,如果 5 月 5 日已经开始,returns 为真,如果 5 月 9 日已经过去,则为假。但是我怎样才能有效地更新 if 语句的瞬时时间值呢?
Template.registerHelper("questionaireUnlocked", function() {
let now = new Date();
let startDate;
let endDate;
if (now > startDate && now < endDate) {
return true;
}
});
感谢您的帮助!
手筒
您可以使用自动运行将时间分配给父模板中的反应变量,例如 Session 变量或 ReactiveVar。
Template.myParentTemplateName.created = function () {
const template = this;
template.autorun(function () {
Meteor.setInterval(Session.set("newTime",new Date()), 6000);
});
}
Template.myParentTemplateName.helpers ({
"questionaireUnlocked" : function () {
const now = Session.get("newTime");
.....
if (now > startDate && now < endDate) {
return true;
}
}
})
希望对您有所帮助。