I'm trying to use a handlebars each iterator in the following chunk of template code:
<table>
<tr><th></th><th>Today</th><th>This Month<br>(To Date)</th><th>Last Month</th></tr>
{{#each Activities}}
{{examineObject this}} - first -
<tr><td>{{examineObject this}}</td>
<td>{{Today}}</td>
<td>{{ThisMonth}}</td>
<td>{{LastMonth}}</td></tr>
{{examineObject this}} - third -
{{/each}}
<tr class='total'><td>Net Change</td>
<td>{{Totals.Today}}</td>
<td>{{Totals.ThisMonth}}</td>
<td>{{Totals.LastMonth}}</td></tr>
</table>
examineObject
is a handlebars helper I have written to simply call JSON.stringify()
on the variable. I'm doing this to evaluate the context. The helper is simply:
examineObject: function(object){
return JSON.stringify(object);
}
When I compile and render the template above, something very odd happens. The context of this
at both the first and third examineObject
call is the individual activity
selected by the each
iterator. However, the context of this
in the second examineObject
call (surrounded by html tags) is the context of the entire template - NOT the context of the individual activity
selected by the each
iterator. Can anyone explain why this would be?