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 d...

问题:

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!


回答1:

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..

  • 发表于 2018-07-10 01:50
  • 阅读 ( 248 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除