Nested #Each values are not available outside of the context
<p>I'm having a nested each pair like this:
{{#each goal in goals}}</p>

<pre><code>&lt;template name="task"&gt;
{{#each goal in goals}}
 {{#each task in relatedTasks goal}}
&lt;li&gt;
&lt;span class="text task"&gt;&lt;a href="#modal-taskedit" data-toggle="modal"&gt;&lt;strong&gt;{{task.taskName}}&lt;/strong&gt;&lt;/a&gt; to {{goal.goalName}}&lt;br&gt; taskid: {{task._id}}
{{task.taskPostpone}}&lt;/span&gt;
    {{#afModal class="btn btn-primary" collection="Tasks" operation="update" doc=task._id}}
  Update {{task.taskName}}
{{/afModal}}
&lt;/li&gt; 
      {{/each}}
 {{/each}}    

&lt;/template&gt;
</code></pre>

<p>and would like to get the value of the task._id in my client.js like here:</p>

<pre><code>Template.task.events({
    'click .task': function() {
    Session.set("selectedTask", this._id);
        //console.log(this._id);
        //console.log(goal._id);
        console.log(task._id);
        //console.log('Click event happened: this._id saved as selectedItem Session variable.');
  } 
  });
</code></pre>

<p>When I click on a task I receive this error on the console: "undefined" and I don't really understand the reason behind. I did some research and found a possible solution: Maybe 'click .task': function(task) should receive the task context or input so it could be able to grasp the meaning of this._id.
I have a {{#afModal doc=task._id}} which also should receive the value of task._id and does not seem to work, although it is placed in the right context I think.
I have a feeling that the two issues are related somehow.</p>