Polymer 如果在dom内重复,则在dom中单击链接时访问当前项

Polymer 如果在dom内重复,则在dom中单击链接时访问当前项,polymer,Polymer,我有以下模板: <template is="dom-repeat" items="{{myItems}}"> <template is="dom-if" if="{{_shouldHaveLink(item)}}"> <a href="#" on-tap="_linkTapped">Link</a> </template> </template> 但是在dom中,如果我不能。似乎项现在超出范围。我怎样才能得

我有以下模板:

<template is="dom-repeat" items="{{myItems}}">
  <template is="dom-if" if="{{_shouldHaveLink(item)}}">
    <a href="#" on-tap="_linkTapped">Link</a>
  </template>
</template>
但是在
dom中,如果我不能。似乎
现在超出范围。我怎样才能得到它

这是一个已知的关于Polymer的
dom repeat
尚未解决的问题,但是在这个场景中有一个简单的解决方法

由于当
if
条件为
false
(作为一种优化)时,不带的模板仅隐藏其内容,因此您可以模拟原始行为,同时避免与
dom if
相关的错误,方法是基于相同的否定条件,使用
hidden
属性替换模板:

<div hidden$="{{!_shouldHaveLink(item)}}">
  <a href="#" on-tap="_linkTapped">Link</a>
</div>

Facebook锚是隐藏的,因为它没有链接

这是一个很好的答案。如果有对
dom repeat
(例如,
this.$.repeater
)的引用,您还应该能够检索
model
对象:
var m=this.$.repeater.modelforement(e.target)
然后你可以参考
m.item
(或者
m.get('item')
我认为在这种情况下它们是一样的。)精确而全面的答案,包括解决方法!谢谢你们两位!
<div hidden$="{{!_shouldHaveLink(item)}}">
  <a href="#" on-tap="_linkTapped">Link</a>
</div>
<a href="#" hidden$="{{!_shouldHaveLink(item)}}" on-tap="_linkTapped">Link</a>