Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I modify a template instance from an event handler in Meteor without Session?
    primarykey
    data
    text
    <p>I am trying to implement a hierarchy of expandable post comments like in e.g. Quora, so that the user can click a comment and see any replies.</p> <p>To this end, I would like to keep track of whether each "comment" template instance is "expanded" or not, toggling the state in the event handler.</p> <p>I could do this using a whole stack Session variables (i.e. one for each comment), but this seems clumsy since there are an arbitrary number of comments on any given page.</p> <p>Below is a snippet of what I'm trying at the moment.</p> <p>JS:</p> <pre><code>Template.comment_item.events = { 'click #comment-content': function( e, instance ) { this.expanded = true; // also tried instance.data.expanded = true } }; Template.comment_item.helpers({ showChildComments: function(){ this.expanded; } }); </code></pre> <p>HTML:</p> <pre><code>&lt;template name="comment_item"&gt; &lt;li class="comment comment-displayed" id="{{_id}}"&gt; &lt;div class="comment-body"&gt; &lt;div id="comment-content"&gt; &lt;!-- some comment data here --&gt; &lt;/div&gt; {{#if showChildComments}} &lt;ul class="comment-children comment-list"&gt; {{#each child_comments}} {{&gt; comment_item}} {{/each}} &lt;/ul&gt; {{/if}} &lt;/div&gt; &lt;/li&gt; &lt;/template&gt; </code></pre> <p>Unfortunately, when I step through, it seems that in the showChildComments helper, the template instance can't see the expanded variable. I did notice in the docs it says instance.data is read only in the events map.</p> <p>Is there any way to modify the template instance within the event map directly?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload