admin管理员组文章数量:1277899
I've read the documentation over and over and have googled with no luck. The docs start explaining this.$ with an example but then they don't give an example for what this.$$ does
As far as I understand it, this.$ will find something in my template with the ID I want. For example - I can use this.$.test.textContent="hey there"
But for this.$$ it just says "dynamically-created nodes" - maybe someone can explain with an example what the difference between static and dynamic created nodes is, and how to use this.$$ - Thank you in advance!
I've read the documentation over and over and have googled with no luck. The docs start explaining this.$ with an example but then they don't give an example for what this.$$ does
As far as I understand it, this.$ will find something in my template with the ID I want. For example - I can use this.$.test.textContent="hey there"
But for this.$$ it just says "dynamically-created nodes" - maybe someone can explain with an example what the difference between static and dynamic created nodes is, and how to use this.$$ - Thank you in advance!
Share Improve this question asked Feb 1, 2017 at 1:15 Bobby BattistaBobby Battista 2,0753 gold badges20 silver badges27 bronze badges 4-
The page you linked to states: For locating dynamically-created nodes in your element's local DOM, the $$ method provides a shorthand for
Polymer.dom(this.root).querySelector()
:this.$$(selector)
– user5734311 Commented Feb 1, 2017 at 1:17 - Yes that's the sentence I was referring to in the question - I just don't know what olymer.dom(this.root).querySelector() does, so I don't know what this.$$(selector) does. And there's no example or explanation. – Bobby Battista Commented Feb 1, 2017 at 4:23
-
That's because it is assumed that people know what JavaScript's
document.querySelector()
does: it selects the first element matching the selector, whereselector
is a String formatted like the one for a CSS rule.this.$$("ul li")
will grab the first<li>
in the first<ul>
. – user5734311 Commented Feb 1, 2017 at 10:05 - very helpful question, thank you – swyx Commented Mar 13, 2018 at 19:36
1 Answer
Reset to default 9Polymer.dom(this.root).querySelector
utilizes the shady DOM API.
Polymer with shady DOM (default in 1.0) doesn't fully polyfill shadow DOM.
To ensure all Polymer features, not natively supported by the browser, are taken into account correctly (like <content>
projection) when using querySelector()
) you need to use the Polymer.dom(...)
wrapper.
this.$
is a getter that returns a static map from element id to the element reference. Elements created bydom-repeat
or hidden bydom-if
or otherwise created dynamically are not included.this.$$()
is a shorthand function forPolymer.dom(this.root).querySelector()
and therefor takes dynamically created elements into account, because it actually queries the DOM when executed.
本文标签: javascriptWhat39s the difference between this and this in PolymerStack Overflow
版权声明:本文标题:javascript - What's the difference between this.$ and this.$$ in Polymer? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741286032a2370274.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论