gpt4 book ai didi

javascript - 更新 html meteor ?

转载 作者:行者123 更新时间:2023-12-03 04:39:26 24 4
gpt4 key购买 nike

我正在尝试根据数据库中的项目(人员)数量输出估计时间(这是一个等待列表)。目前,我以名为 countNumber> 的快速表单保存一个值。 每次都将其设置为 1。然后,我通过查找 countNumber = 1 的所有项目(所有项目)来获取所有项目的计数。然后,我尝试使用 getElementById() 更新 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;

...

},
}
});

最佳答案

您应该将其放入助手而不是 Hook 中。

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

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

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

关于javascript - 更新 html meteor ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43146819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com