Why is the find query not returning any data when using the "qnum" variable argument as a value? Could it be due to the scope limitation of variables inside an object?
Quiz.js file
Questions = new Mongo.Collection("questions");
if (Meteor.isClient) {
var qnum = 1;
Template.question.events({
"click #submit-btn": function (event, template) {
//Increase question number each time user clicks on submit button to load next question
qnum += 1;
}
});
Template.body.helpers({
questions: function (qnum) {
return Questions.find({qnum: qnum});
}
});
}
Quiz.html file
<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>
Questions db collection
{ "_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" ] }