Javascript 如何在meteor模板助手中执行事件冒泡

Javascript 如何在meteor模板助手中执行事件冒泡,javascript,events,meteor,Javascript,Events,Meteor,我试图捕获整个{{{each categories}}的数据,但是我的按钮.toggle addToSet我用来做的不是一直捕获到顶部,它只是捕获{{{each categories}中的{{each categories}的数据,不幸的是我需要的数据不在那里,因此,我需要一种方法来捕获{{{each set}}之外的数据,一直到{{{each categories} 这就是它在HTML中的外观 <ul> {{#each categories}} <li class="

我试图捕获整个
{{{each categories}}
的数据,但是我的按钮
.toggle addToSet
我用来做的不是一直捕获到顶部,它只是捕获
{{{each categories}
中的
{{each categories}
的数据,不幸的是我需要的数据不在那里,因此,我需要一种方法来捕获
{{{each set}}
之外的数据,一直到
{{{each categories}

这就是它在HTML中的外观

<ul>
  {{#each categories}}
  <li class="myIdd">
    <div class="row col s12 m7">
      <div class="card" id="cardId">
        <div class="card-image waves-effect waves-block waves-light">
          <a href="/latestSingle/{{_id}}"><img src="{{better_featured_image.source_url}}"></a>
        </div>
        <div class="card-content">
          <h5 class=" truncate grey-text text-darken-4">{{title.rendered}}</h5>
          <a href="/latestSingle/{{_id}}">MORE</a> <a href="#modal2" class="modal-trigger waves-effect waves-light" onclick="Materialize.showStaggeredList('#bottom-options')"><i class="waves-effect waves-teal small material-icons right">playlist_add</i></a>{{>
          likePartial}}{{> reblogPartial}}

          <!-- The modal below is what brings up all the sets the user has created so that the user can pick with set they wat to save the article in  -->

          <div id="modal2" class="modal bottom-sheet">
            <div class="modal-content">
              <div class="row">

                <!-- data being captured is only below this, but i need it to capture up until li class ="myIdd" -->

                {{#each set}}
                <div class="col s6 m6 addSet teal">
                  <div class="card ">
                    <div class="card-image">
                      <span class="card-title cardSet">{{name}}</span>
                    </div>
                    <div class="card-footer">

                    <!-- This button is what i'm using to try and capture the data all the way to li class ="myIdd" -->

                      <button type="button" class="btn toggle-addToSet" name="button" data-setid="{{s._id}}">add Article Id to this Set!</button>
                    </div>
                  </div>
                </div>
                {{/each}}

                <!-- end of capture -->

              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </li>
 {{/each}}
</ul>
其中
var ob=此
仅用于捕获

            {{#each set}}
                    <div class="col s6 m6 addSet teal">
                      <div class="card ">
                        <div class="card-image">
                          <span class="card-title cardSet">{{name}}</span>
                        </div>
                        <div class="card-footer">

                        <!-- This button is what I'm using to try and capture the data all the way to li class ="myIdd" -->

                          <button type="button" class="btn toggle-addToSet" name="button" data-setid="{{s._id}}">add Article Id to this Set!</button>
                        </div>
                      </div>
                    </div>
                    {{/each}}

当您调用
{{{each set}}…{{/each}}
时,您正在更改内部块的上下文

我建议使用
{{{each catSet in set}}…{{/each}
这不会改变
each
块的上下文,但会引入新的
catSet
变量,如下所示

就你而言:

<ul>
  {{#each categories}}
  <li class="myIdd">
    <div class="row col s12 m7">
      <div class="card" id="cardId">
        <div class="card-image waves-effect waves-block waves-light">
          <a href="/latestSingle/{{_id}}"><img src="{{better_featured_image.source_url}}"></a>
        </div>
        <div class="card-content">
          <h5 class=" truncate grey-text text-darken-4">{{title.rendered}}</h5>
          <a href="/latestSingle/{{_id}}">MORE</a> <a href="#modal2" class="modal-trigger waves-effect waves-light" onclick="Materialize.showStaggeredList('#bottom-options')"><i class="waves-effect waves-teal small material-icons right">playlist_add</i></a>{{>
          likePartial}}{{> reblogPartial}}

          <!-- The modal below is what brings up all the sets the user has created so that the user can pick with set they wat to save the article in  -->

          <div id="modal2" class="modal bottom-sheet">
            <div class="modal-content">
              <div class="row">

                <!-- data being captured is only below this, but i need it to capture up until li class ="myIdd" -->

                {{#each catSet in set}}
                <div class="col s6 m6 addSet teal">
                  <div class="card ">
                    <div class="card-image">
                      <span class="card-title cardSet">{{catSet.name}}</span>
                    </div>
                    <div class="card-footer">

                    <!-- This button is what i'm using to try and capture the data all the way to li class ="myIdd" -->

                      <button type="button" class="btn toggle-addToSet" name="button" data-setid="{{s._id}}">add Article Id to this Set!</button>
                    </div>
                  </div>
                </div>
                {{/each}}

                <!-- end of capture -->

              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </li>
 {{/each}}
</ul>
    {{{#每个类别}
  • {{title.rendered} {{> 像部分}{{>reblogPartial}} {{{#集合中的每个catSet} {{catSet.name} 将文章Id添加到此集合! {{/每个}}
  • {{/每个}}
{{#each categories}}
capture everything in here
{{/each}}
<ul>
  {{#each categories}}
  <li class="myIdd">
    <div class="row col s12 m7">
      <div class="card" id="cardId">
        <div class="card-image waves-effect waves-block waves-light">
          <a href="/latestSingle/{{_id}}"><img src="{{better_featured_image.source_url}}"></a>
        </div>
        <div class="card-content">
          <h5 class=" truncate grey-text text-darken-4">{{title.rendered}}</h5>
          <a href="/latestSingle/{{_id}}">MORE</a> <a href="#modal2" class="modal-trigger waves-effect waves-light" onclick="Materialize.showStaggeredList('#bottom-options')"><i class="waves-effect waves-teal small material-icons right">playlist_add</i></a>{{>
          likePartial}}{{> reblogPartial}}

          <!-- The modal below is what brings up all the sets the user has created so that the user can pick with set they wat to save the article in  -->

          <div id="modal2" class="modal bottom-sheet">
            <div class="modal-content">
              <div class="row">

                <!-- data being captured is only below this, but i need it to capture up until li class ="myIdd" -->

                {{#each catSet in set}}
                <div class="col s6 m6 addSet teal">
                  <div class="card ">
                    <div class="card-image">
                      <span class="card-title cardSet">{{catSet.name}}</span>
                    </div>
                    <div class="card-footer">

                    <!-- This button is what i'm using to try and capture the data all the way to li class ="myIdd" -->

                      <button type="button" class="btn toggle-addToSet" name="button" data-setid="{{s._id}}">add Article Id to this Set!</button>
                    </div>
                  </div>
                </div>
                {{/each}}

                <!-- end of capture -->

              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </li>
 {{/each}}
</ul>