Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing this in callback for non-collection
    primarykey
    data
    text
    <p>I'm going through the <a href="http://meteor.com/examples/leaderboard" rel="nofollow">leaderboard</a> example right now, and I've finished it, but I'm not fully satisfied with my implementation of the <em>add</em> functionality.</p> <p>To start with, we have</p> <pre><code>Template.player.events({ 'click': function () { Session.set("selected_player", this._id); } }); </code></pre> <p>I find it a little bit confusing how <code>this</code> is associated with the player collection, but I imagine this has to do with the <code>&lt;template</code> part. I am also able to do</p> <pre><code>Template.leaderboard.events({ 'click input.delete': function () { Players.remove(this._id); } </code></pre> <p>...which does remove the player with the associated button entry.</p> <hr> <p>Now for the actual question part: I have added this to the bottom of the leaderboard template:</p> <pre><code>&lt;div&gt; Add player: (Name &lt;input required name="name" id="name"&gt;) (Score &lt;input required name="score" id="score"&gt;) &lt;input class="add" type="button" value="Add"&gt; &lt;/div&gt; </code></pre> <p>This works fine, and I have <code>Template.leaderboard.events['click input.delete']</code> working fine, but in order to get the values I use:</p> <pre><code>'click input.add': function () { var name = document.getElementById('name').value, score = document.getElementById('score').value; </code></pre> <p>It would make a lot of sense to me if I were able to use <code>this</code> in some way, or use the event to somehow get the values that correspond the inputs. This not only makes sense to me from a design standpoint, but it would also cover the case of having more than one of these kinds of forms displaying simultaneously.</p> <p>So in short is there any way to get elements that are near the target element in the context of an event?</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