[英]Can I use jquery within my custom Polymer elements?
The Polymer documentation says: Polymer文档说:
Polymer provides a custom API for manipulating DOM such that local DOM and light DOM trees are properly maintained. Polymer提供了一个用于操作DOM的自定义API,以便正确维护本地DOM和轻型DOM树。 These methods and properties have the same signatures as their standard DOM equivalents, except that properties and methods that return a list of nodes return an Array, not a NodeList. 这些方法和属性与其标准DOM等效项具有相同的签名,除了返回节点列表的属性和方法返回Array而不是NodeList。
Note: All DOM manipulation must use this API, as opposed to DOM API directly on nodes. 注意:所有DOM操作都必须使用此API,而不是直接在节点上使用DOM API。
Jquery has a lot of useful methods though, which make my life easier, like toggleClass
, hasClass
, addClass
, one
... Jquery有很多有用的方法,这让我的生活更轻松,比如toggleClass
, hasClass
, addClass
, one
...
I have been able to use some of these methods without consequence in my elements, but I am wondering what exactly the semantics are behind the bold part of the above quote, so I can reason about things more clearly. 我已经能够使用其中一些方法而不会影响我的元素,但我想知道上面引用的粗体部分背后的语义究竟是什么,所以我可以更清楚地推理事情。
Note: I'm not talking about using jquery in the main document, I am talking about using it when I am inside the shadow boundary, like in an element's ready
callback for instance. 注意:我不是在讨论在主文档中使用jquery,我正在讨论当我在阴影边界内时使用它,就像在元素的ready
回调中一样。
You can, actually. 你可以,实际上。 You'll just have to use Polymer.dom(this.root).querySelector
and wrap that returned element in jquery. 你只需要使用Polymer.dom(this.root).querySelector
并将返回的元素包装在jquery中。
Here's an example. 这是一个例子。 http://jsbin.com/purudu/edit?html,output http://jsbin.com/purudu/edit?html,output
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.