在Polymer中,this.$和this.$$有什么区别? [英] What's the difference between this.$ and this.$$ in Polymer?

查看:134
本文介绍了在Polymer中,this.$和this.$$有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经一遍又一遍地阅读了文档,并且在Google上没有运气. docs 开始用一个例子解释.不要为此事举例.$$

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

据我了解,this.$会在我的模板中找到具有所需ID的东西.例如-我可以使用this.$.test.textContent ="hey there"

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!

推荐答案

Polymer.dom(this.root).querySelector利用了可疑的DOM API.

Polymer.dom(this.root).querySelector utilizes the shady DOM API.

具有阴影DOM(默认值为1.0)的聚合物不能完全填充阴影DOM.

Polymer with shady DOM (default in 1.0) doesn't fully polyfill shadow DOM.

要确保在使用querySelector()时正确考虑到浏览器本身不支持的所有Polymer功能(例如<content>投影),则需要使用Polymer.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.$是一个获取程序,它从元素ID返回到元素引用的静态映射.不包括由dom-repeat创建的元素或由dom-if隐藏的元素或以其他方式动态创建的元素.

  • this.$ is a getter that returns a static map from element id to the element reference. Elements created by dom-repeat or hidden by dom-if or otherwise created dynamically are not included.

this.$$()Polymer.dom(this.root).querySelector()的简写函数,因此考虑到动态创建的元素,因为它在执行时实际上会查询DOM.

this.$$() is a shorthand function for Polymer.dom(this.root).querySelector() and therefor takes dynamically created elements into account, because it actually queries the DOM when executed.

这篇关于在Polymer中,this.$和this.$$有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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