私は、コレクションの数に基づいて推定待ち時間を表示するアプリケーションを作成しています。私が抱えている問題は、ページが読み込まれたり、waitTimeの表示がリフレッシュされたときです。最初に0が表示され、約1秒後にカウントに基づいて実際のwaitTimeが表示されます。私はこれが、変数が初期カウントを0にしてから実際のカウントを取得してwaitTimeを表示するように、コレクションからカウントを取得するのが遅れていることを前提としていますか?流星での変数の表示を遅らせるには?
ロードまたはリフレッシュ時に正確な待機時間のみを表示する方法はありますか?
JS:
Template.home.helpers({
waitTime: function() {
var totalCount = Students.find().count();
var hour = totalCount/4;
if(totalCount < 4){
return 15*totalCount + " minutes"
}else if(totalCount >= 4 && totalCount%4 == 0){
return hour + " hour(s)";
}else if(totalCount >= 4 && totalCount%4 == 1){
hour = hour - .25;
return hour + " hour(s)" + " 15 minutes";
}else if(totalCount >= 4 && totalCount%4 == 2){
hour = hour - .5;
return hour + " hour(s)" + " 30 minutes";
}else if(totalCount >= 4 && totalCount%4 == 3){
hour = hour - .75;
return hour + " hour(s)" + " 45 minutes";
}
}
});
HTML:
<template name= "home">
<body>
<h2 id="insert">Approximate Wait Time: {{waitTime}}</h2>
<div class="col-lg-6 col-lg-offset-3">
<!-- Quick form from autoform package creates sign in form and populates collection with data-->
{{>quickForm id="studentForm" collection="Students" type="insert" template="bootstrap3-horizontal" label-class="col-sm-3" input-col-class="col-sm-9"}}
</div>
</body>
</template>