在meteor中隔离模板区域以简化DOM导航

在meteor中隔离模板区域以简化DOM导航,meteor,handlebars.js,Meteor,Handlebars.js,使用template.find查找特定模板实例中的DOM元素非常有用。但是当模板在一些标记上迭代{{{each}}而不使用子模板时会发生什么呢 <template name="top"> {{#each items}} <img src="{{src}}"> <a href="{{url}}">Click me</a> {{/each}} </template> Tempalte.events( 'clic

使用
template.find
查找特定模板实例中的DOM元素非常有用。但是当模板在一些标记上迭代
{{{each}}
而不使用子模板时会发生什么呢

<template name="top">
  {{#each items}}
    <img src="{{src}}">
    <a href="{{url}}">Click me</a>
  {{/each}}
</template>

Tempalte.events(
  'click a': (event, template) ->
    template.find('img')           # This doesn't do the trick
                                   # Is there a better way?
)

{{{#每项}
{{/每个}}
临时事件(
'单击a':(事件、模板)->
template.find('img')#这不管用
#有更好的办法吗?
)
是否有办法轻松访问与点击事件相关的
img
元素?


我知道我可以使用
event.target
或创建另一个模板,然后在
{{each}
块中使用它。我想知道是否有更好/更短的方法来做这件事。

你可以在img中添加一个@index来选择它(使用js或CSS)

似乎Meteor的把手实现中尚未实现
@index