【发布时间】:2015-07-12 15:46:28
【问题描述】:
在使用“qnum”变量参数作为值进行查找查询时,它不会返回任何数据。是不是因为对象内部变量作用域的限制?
测验.js 文件
Questions = new Mongo.Collection("questions");
if (Meteor.isClient) {
var qnum = 1;
Template.question.events({
"click #submit-btn": function (event, template) {
//Increment question number when user click on submit button which loads the next question
qnum += 1;
}
});
Template.body.helpers({
questions: function (qnum) {
return Questions.find({qnum: qnum});
}
});
}
测验.html 文件
<div class="quiz">
<div class="score-board">
{{#each questions}}
{{> question}}
{{/each}}
</div>
</div>
</body>
<template name="question">
<div class="qa-wrapper" id="{{qnum}}">
<div class="questions">{{title}}</div>
<div class="options">
{{#each options}}
<input type="checkbox" name="{{this}}"/>{{this}} <br />
{{/each}}
<button id="submit-btn">Submit</button>
</div>
</div>
</template>
问题数据库集合
{ "_id" : ObjectId("55a207a21c4dbe14cf9837c7"), "qnum" : 1, "title" : "Question 1", "options" : [ "A", "B", "C", "D" ] }
{ "_id" : ObjectId("55a207b31c4dbe14cf9837c8"), "qnum" : 2, "title" : "Question 2", "options" : [ "A", "B", "C", "D" ] }
【问题讨论】:
标签: javascript mongodb meteor