How to pass parameters to Polymer 2.0 on-tap functions?

I am using Polymer 2.0 and I have one dom-repeatfor different cards. I want to remove the card when I click on it.

So, I tried this on-tap=deleteNote([[index]])one that uses the index from dom-repeat. However, Polymer does not perform a function.

What am I doing wrong?

+4
source share
4 answers

Another solution might be object datasetin event.target. You can define your properties using the prefix data-:

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

And in your listener doSomething()you can get an object dataset:

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

model .

, event.model.index.

+2

, , . .

, . [[index]] , .

:

<div on-tap='_deleteNote' indexed$='[[index]]'>

script:

_deleteNote(e) {
  var index = e.target.getAttribute('indexed');
  ...
}

index, , .

Polymer, Polymer 2.0.

class Foo extends Polymer.GestureEventListeners(Polymer.Element) {}

: https://www.polymer-project.org/2.0/docs/devguide/gesture-events#using-gesture-events

What is a hybrid element: https://www.polymer-project.org/2.0/docs/devguide/hybrid-elements

-1
source

on-tapdoes not appear to be implemented in Polymer 2.0. If you use on-click, then it will work.

EDIT: see below comment.

-2
source

Source: https://habr.com/ru/post/1675208/


All Articles