【发布时间】:2019-06-04 16:10:32
【问题描述】:
我正在尝试显示在表单中提交的所有信息的总和。
Template.SingleDailylog.helpers({
personInCharge: ()=>{
const id = FlowRouter.getParam('id');
const profile = Dailylog.findOne({_id:id});
const name = profile.personInCharge;
return name;
}
});
<div class="form-group col-md-6">
<input value="{{personInCharge}}" type="text" class="form-control" placeholder="Name">
<label for="first">Person In Charge</label>
</div>
这确实插入了信息,但我仍然收到错误:
meteor.js?hash=0504f43f667698535416b00eb44eb6f53161cb63:1048 模板助手中的异常:TypeError:无法读取未定义的属性“personInCharge” 在 Object.personInCharge (http://localhost:3000/app/app.js?hash=e537a3bd311bc41765fe473a7cd9cf9609139dc9:8544:26) 在http://localhost:3000/packages/blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:3051:16 在http://localhost:3000/packages/blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:1715:16 在http://localhost:3000/packages/blaze.js?hash=adc5286b78e5c0f8e7f56a602f77eefb5def6bf1:3103:66 在 Function.Template._withTemplateInstanceFunc
我怎么会出错,但显示的数据是正确的?这使我无法保存对数据的编辑。
【问题讨论】:
-
这很可能是因为在第一次渲染中订阅还没有准备好,因此助手抛出了一个错误。然后,一旦 sub 准备好,数据就可用,没有错误,并且您的输入值设置为任何名称。
标签: javascript meteor