更新html流星?

问题描述:

我想输出估计的时间基于我的数据库(这是一个等待列表)中的项目(人)的数量。目前我在名为countNumber.的快速格式中保存一个值,每次只设置为1。然后,我通过查找countNumber = 1(全部)的所有项目来计算所有项目的数量。然后我尝试使用getElementById()更新html。更新html流星?

我遇到的问题是,当我将一个人添加到数据库时,估计的时间会适当增加。但是,当我刷新页面的HTML重置为0,就像输入的最初的HTML。

我该如何解决这个问题,以便即使页面刷新时html也会始终显示适当的时间?

HTML代码:

<head> 
    <title>Wait List</title> 
</head> 

<template name= "home"> 
    <body> 
     <h2 id="insert">Approximate Wait Time: 0 Minutes</h2> 
     <div class="col-lg-6 col-lg-offset-3"> 
      {{>quickForm id="studentForm" collection="Students" type="insert" template="bootstrap3-horizontal" label-class="col-sm-3" input-col-class="col-sm-9"}} 
     </div> 
    </body> 
</template> 

JS代码:

AutoForm.hooks({ 
    studentForm: 
{ 
    onSuccess: function (insert,result) { 
     var totalCount = Students.find({countNumber:1}).count(); 
     var waitTime = "Approximate Wait Time: " + totalCount*15 +" Minutes"; 
     document.getElementById("insert").innerHTML = waitTime; 

     ... 

    }, 
} 
}); 

你应该放到一个帮手,而不是挂钩这一点。

Template.home.helpers({ 
    waitTime: function(){ 
     var totalCount = Students.find({countNumber:1}).count(); 
     var waitTime = totalCount*15; 
     return waitTime; 
    } 
}); 

并将html中的<h2>行更改为此。

<h2 id="insert">Approximate Wait Time: {{waitTIme}} Minutes</h2>