【发布时间】:2014-07-23 16:59:58
【问题描述】:
Template.prices.rendered = function() {
OrderFormContent = new Meteor.Collection(null);
var orderSubmission = function() {
//code that inserts stuff into the OrderFormContent collection
//the key **sqft** is assigned the value of **4000** };
orderSubmission();
};
Template.prices.helpers({
sqft: function() {
return OrderFormContent.findOne().sqft;
}
});
上面的代码没有加载。 Meteor 尝试创建 {{sqft}} 的助手,但不能因为 OrderFormContent 直到页面呈现后才被定义。看来 Meteor 试图在页面渲染之前定义帮助器。
但我需要定义这个助手。而且我只需要在模板渲染(而不是创建)之后定义它。
我不能只将Template.prices.helpers 嵌套在Template.prices.rendered 中。
澄清:
如果我注释掉 Template.prices.helpers 代码,页面将加载。如果我随后在控制台中手动运行OrderFormContent.findOne().sqft,则返回值 4000。
当我取消注释 Template.prices.helpers 代码时,页面无法加载,我收到 Exception from Deps recompute function: ReferenceError: OrderFormContent is not defined 错误。
【问题讨论】:
-
为什么?从您发布的代码中,我看不出您以后要定义帮助程序的任何原因。
-
什么意思?在定义
{{sqft}}助手时,OrderFormContent集合不存在。所以 Meteor 抛出一个错误,说OrderFormContent是未定义的,页面甚至没有加载。
标签: meteor