如何在Polymer 2.0 on-tap功能中传递参数? [英] How to pass parameters in Polymer 2.0 on-tap function?

查看:93
本文介绍了如何在Polymer 2.0 on-tap功能中传递参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Polymer 2.0,我有一个 dom-repeat 用于不同的待办事项卡。我想要做的是点击它时取出卡。

I'm using Polymer 2.0 and I have a dom-repeat for different to-do cards. What I want to do is remove the card when I click on it.

所以我尝试了这个 on-tap = deleteNote([[index]]),它使用了来自的索引 DOM的重复。然而,Polymer不执行该功能。

So I tried this on-tap=deleteNote([[index]]) which uses the index from the dom-repeat. However Polymer doesn't execute the function.

我做错了什么?

推荐答案

另一个解决方案可能是 event.target 中的数据集对象。您可以使用数据 - 前缀定义属性:

Another solution could be the dataset object within the event.target. You can define your properties with the data- prefix:

<div on-tap="doSomething" data-item$="[[item]]"></div>

在你的 doSomething()听众中可以获得数据集对象:

And within your doSomething() listener you can get the dataset object:

doSomething(event) {
  const item = event.target.dataset.item;
  ...
}

这篇关于如何在Polymer 2.0 on-tap功能中传递参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆