[英]Get data from Meteor Collection for CountdownTimer
我想將CountdownTimer設置為用戶選擇的特定日期。 我將日期保存在流星收藏中
Template.addDate.events({
'submit form':function(event){
var closeDate = $('[name="date"]').val();
Date.insert({
closeDateDB: closeDate,
)};
}
});
現在,我想從集合中獲取此數據,並將我的計時器中的新結束時間設置為該選擇的日期。
Meteor.startup(function () {
var endtime = Data.findOne(???);
timeinterval = setInterval(function () {
Meteor.call("getCurrentTime", function (error, result) {
Session.set("time", result);
var t = getTimeRemaining(endtime);
Session.set("t", t);
});
}, 1000);
});
我如何在數據庫中獲取插入的日期並將其用於計時器? 如何填寫“ ???” 在
Data.findOne(???);
編輯___
我試圖更好地定義我想要實現的目標。 如果用戶進入該站點,則應填寫表格。 像這樣:
Template.addQuestions.events({
'submit form':function(event){
event.preventDefault();
var questionText = $('[name="questionName"]').val();
var categoryText = $('[name="categoryName"]').val();
var closeDate = $('[name="date"]').val();
Questions.insert({
closeDateDB: closeDate,
categoryDB1: categoryText,
questionDB: questionText,
createdAt: new Date(),
}, function (error,results){
Router.go('decision', {_id:results});
}
如您所見,我得到了closeDateDB,用戶可以通過日期選擇器選擇日期。 我用tsega:bootstrap3-datetimepicker
。 此后,用戶將被重定向到新創建的站點。
在這個新站點上,我想獲取我的countdowntimer的closeDate 例如“ 12/24/2015”作為Meteor.startup();
計數器應從currentTime(提交表單時的實際日期/時間)到用戶之前在表單中輸入的closeDate日期/時間進行計數。 當實際日期/時間> closeDate
,應該關閉創建的站點,並且用戶將被重定向到另一個頁面。
我正在將其作為建模問題閱讀。 當你有:
Date.insert({ closeDateDB: closeDate });
您正在MongoDB中使用單個鍵closeDateDB創建記錄。
首先,這不是由用戶索引的,因此不清楚您打算如何處理這些事件。 Meteor.startup()
將為每個新用戶運行(在客戶端或服務器端,具體取決於您在何處定義)。 每個人都有自己的行動嗎? 將來發生多個事件時會發生什么?
其次,當時間> closeDate
並且事件已過去時會發生什么?
一些可能性:
// find a single random event in the future
Date.findOne({ closeDateDB: { $gte: new Date() } });
// find the next event
Date.findOne({ closeDateDB: { $gte: new Date() } },
{ sort: { closeDateDB: -1}} );
// find the next event for this user (assuming the userId key was added on insert)
Date.findOne({ userId: Meteor.userId(), closeDateDB: { $gte: new Date() } },
{ sort: { closeDateDB: -1}, limit: 1 } ); )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.