Hey guys,
I have a very simple situation here, but Blaze is managing to drive me crazy with its cryptic documentation and confusing syntax.
I have a survey collection, with an array of questions inside. This array contains only strings that point to the questions’ ID’s.
I want to create a simple page where all surveys and questions inside of them are shown.
Therefore I created two templates on the same html file: one to loop through the surveys and the second to loop through the questions. My goal is that for each survey found, the page prints each question found. Tried a million different things and it doesn’t work. Here is my code:
answer.html
<template name="Answer">
<div class="container">
<div class="row">
<div class="col s12">
{{#each survey in surveys}}
<h4>{{survey.name}}</h4>
{{> Question (questions survey)}}
{{/each}}
</div>
</div>
</div>
</template>
<template name="Question">
<div class="row">
<div class="col s12">
{{#each question in questions}}
<h6>{{question.text}}</h6>
{{/each}}
</div>
</div>
</template>
answer.js
if(Meteor.isClient){
let companyId = Meteor.userId(); // Grabs current logged-in company's ID
Meteor.subscribe('surveys',companyId); // Subscribes to current company's surveys
Template.Answer.helpers({
surveys(){
return Surveys.find({companyId: companyId}); // Returns current company's surveys
}
});
Template.Question.helpers({
questions(survey){
console.log(survey);
const questions = survey.questions; // Grabs questions array from the passed survey object - REMEMBER: array contains only question id's
for(let i in questions){
const question = Questions.find({_id: questions[i]},{fields: {questionText:1}}); // Returns question text for each question ID passed
return question;
}
}
})
}
Result is this error: Exception in queued task Error: No such function: questions
Any idea what I could do? Thanks!