Change event is not working

Hi, 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. Currently, the student name is not showing in the table without throwing any errors.

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.{
   'change #dropdown': function(event,template){
     var selectedValue = $(;
     var array = subject.findOne({subjectCode:selectedValue}, {fields:{_id:0, enrollment:1}});
   student: function() {
     var listOfStudent = Session.get('studentEnrolled');
     return student.find({studentID:{$in:listOfStudent}});

And HTML code:

<template name="student">
    {{#each student}}
      <td><input type="checkbox" value=""></td>
      <td><textarea rows="1"></textarea></td>

I’m going to take a guess that enrollment is an array of enrolled student IDs?

First of all, you are taking the whole subject document andwrapping that array into another array here:


Which means when you search here:

return student.find({studentID:{$in:listOfStudent}});

You are passing an array with a document in it, instead of the enrollments array.

What you want to do is store the enrollments in the session:

Session.set('studentEnrolled', array.enrollments);

I’d also recommend renaming the variable array since it’s not an array, and that probably contributed to your confusion

EDIT: I see from your question on SO that my guess about your schema was right:

1 Like

That’s why it looks kind of different with an actual array from console. It is working now ! Thank you a lot :smiley: