【发布时间】:2014-03-19 15:55:28
【问题描述】:
我正在使用 Meteor 制作一个测试/测验应用程序,并将所有问题、可能的答案等存储在本地 MongoDB 中,如下所示:
{
type: "someType",
skillType: "someSkillType",
questions: [
{
questionID: 1,
question: "Some question",
answer: 2,
option1: "Some possible answer",
option2: "Another one",
option3: "Etc."
},
{
questionID: 2,
question: "Some question 2",
answer: 1,
option1: "Some possible answer",
option2: "Another one",
option3: "Etc."
}
]
}
等等。我已经测试并绝对确定问题不是我的Meteor.Collection、Meteor.publish / Meteor.subscribe 或与数据库的连接。数据就在那里,我可以从控制台访问它就好了。
我的模板如下所示:
<template name="test">
<form name="testForm" id="testForm" role="form">
{{#each testQuestions}}
<div class="jumbotron">
<p><b>{{questionID}}.</b> {{question}}</p>
<div class="radio">
<label>
<input type="radio" name="qNumber{{questionID}}" value="1" required>
{{option1}}
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="qNumber{{questionID}}" value="2">
{{option2}}
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="qNumber{{questionID}}" value="3">
{{option3}}
</label>
</div>
</div>
{{/each}}
</form>
</template>
然后我制作了一个模板助手来获取数据:
Template.test.testQuestions = function () {
questionsAll = allQuestions.findOne({"type": "someType", "skillType": "someSkillType"}, {fields: {"_id": 0, "type": 0, "skillType": 0, "questions.answer": 0 }});
questionsAll1 = EJSON.toJSONValue((questionsAll.questions)); // I've tried both with and without this part.
return questionsAll1;
}
但是它不起作用,没有渲染任何内容,并且我在控制台中收到一个很长的错误,开始于:
"Exception from Deps recompute function: .observeChanges@.......
如果我直接在模板助手中创建一个静态数组,它可以正常工作。我觉得我已经尝试了一切,我根本无法找出原因。有什么帮助或想法吗?
【问题讨论】:
标签: javascript arrays json mongodb meteor