2015-12-15 67 views
0

我想將CountdownTimer設置爲用戶選擇的特定日期。我在流星集合從Meteor Collection獲取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(???); 

EDIT___

我嘗試定義什麼更好我想要實現。 如果用戶進入該網站,他應填寫表格。就像這樣:

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,用戶可以通過datepicker選擇一個日期。我用tsega:bootstrap3-datetimepicker。在此之後,用戶被重定向到一個新創建的網站。

在這個新的網站,我想獲得例如closeDate 「2015年12月24日」我countdowntimer作爲Meteor.startup();結束時間計數器應該從currentTime的,實際的日期/時間算提交表單時,直到用戶在表單中輸入的closeDate日期/時間。當實際日期/時間>closeDate時,應關閉創建的網站,並將用戶重定向到其他網頁。

+0

我不知道大局觀做法是什麼,但你有沒有見過這個包:[mizzao:時間同步(https://atmospherejs.com/mizzao/timesync) ? – ejb

+0

你想找到哪個文件不清楚這個問題。你能否添加更多關於你想達到的信息? –

回答

0

我正在讀這是一個建模問題。當你有:

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 });) 
+0

試圖更好地定義問題 – decisionMaker

+0

正確,所以我認爲我的答案涵蓋了所有可能的情況。少了什麼東西? –

+0

如果我嘗試你的答案,它會拋出未捕獲的錯誤:無法識別的操作符:$ ge。對不起,我是meteor.js的初學者。 $ ge運營商在這裏做什麼? – decisionMaker

相關問題