RoyalRagger
RoyalRagger

Reputation: 73

Use an attribute from an HTML-Tag in Polymer

I'm using Polymer and I am encountering a Problem. I think there is a good solution, but I still don't have the perfect understanding of polymer.

In my template I get a dom-repeat which gets me some _itemsas item. item.name returns the name of the item, it works just fine. Now I want to use this name to display it in a tooltip, so I call the function on-mouseenter="_showTooltip".

My function looks like this:

_showTooltip: function(e) {
    var item = Polymer.dom(e).rootTarget;
    //........here I get Information out of my item to use it in my tooltip and display it
}

How can I transfer the information of my original item to this function?

Thanks in advance!

Upvotes: 1

Views: 50

Answers (1)

mishu
mishu

Reputation: 5397

You did not mention or tag which version of Polymer you're using so I will point you to the docs for Polymer 2 because that's what I use, but I am guessing something similar must exist for Polymer 3 also.

Any event triggered from elements rendered inside a dom-repeat will get a model key added, under which you will have the context, so you will have your item from HTML there.

You can see that in the docs here.

To start you can try to:

_showTooltip: function(e) {
    var item = Polymer.dom(e).rootTarget;
    //........here I get Information out of my item to use it in my tooltip and display it
    console.log(e.model); debugger;
}

and continue from there..

Upvotes: 1

Related Questions