everyone. I would like the students who enroll a subject are shown in a table when this subject is selected in a dropdown list. The ID of these students is stored in an array. The problem is that this ID array retrieved from the document looks kind of strange. seem like there is an array in an array. Like this shown in the console: shown in console
{enrollment: Array(2)}
enrollment: Array(2)
0: "b1602231"
1: "B1560124"
length: 2
__proto__: Array(0)
__proto__: Object
And it throwed an error: Exception in template helper: Error: $in needs an array
So how could I solve this? I would really appreciate it if someone can give me some idea.
Below is the event handler and helper.
Template.subject.events({
‘change #dropdown’: function(event, template) {
var selectedValue = $(event.target).val();
var array = subject.findOne( { subjectCode:selectedValue }, { fields:{ _id:0, enrollment:1 } } );
Session.set(‘studentEnrolled’,array);
}
});
Template.student.helpers({
student: function() {
var listOfStudent = Session.get( ‘studentEnrolled’ );
return student.find( { studentID: { $in:listOfStudent } } );
}
});
//HTML
<template name="student">
{{#each student}}
<tr>
<td>{{name}}</td>
</tr>
{{/each}}
</template>
__proto__attribute confuses me.