使用Meteor从Mongodb集合中调用把手帮助器时,没有此类模板错误

No such template error when calling handlebars helper from Mongodb collection with Meteor

我有一个HTML模板,我想在其中显示使用车把帮助器存储在mongo对象中的值。

HTML-我想将答案1显示为存储在mongo中"问题1"下的字符串。

1
2
3
4
5
6
7
8
9
10
<template name="preferencesView">

    Here are your preferences

        <p> Answer to question 1 {{> answer1}}</p>
        <p> Answer to question 2 {{> answer2}}</p>

   

</template>

这是我的.js帮助器。 (为什么它不将answer1作为模板存储在这里,而{{answer1}}可以在我的HTML文档中调用?)

1
2
3
4
5
6
Template.preferencesView.helpers = ({
answer1: function () {
    return Preferences_col.find({userId: Meteor.userId()}
        );
}
});

也-我是否在上述帮助程序中使用正确的mongo调用来查找所需的数据? (问题1)这是在表单提交事件中创建的示例。

1
{"Question1" :"Yes","Question2" :"Yes","userId" :"hqWJNWLjwfggJtbPi","submitted" : 1389406102126,"_id" :"fWEpMXX4w9wfzLg5g" }

当我在终端中运行流星时,它没有遇到任何错误。但是,在我的浏览器控制台中,我收到"来自Deps重新计算的异常:错误:无此类模板'answer1'"

PS-这是我关于Stackoverflow的第一篇文章,因此,如果您需要更多信息,请告诉我!


如果我是对的,那么您就说错了。 {{> templateName}}与调用模板一起使用,而{{helperName}}与调用助手一起使用。同样,除了返回find查询的结果之外,还返回findOne查询的结果(作为find查询的结果),即使大小仅为1,也会有一些问题。 >