简体   繁体   English

我可以在自定义Polymer元素中使用jquery吗?

[英]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有很多有用的方法,这让我的生活更轻松,比如toggleClasshasClassaddClassone ...

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.

相关问题 我可以在 TinyMCE 中使用 Polymer 元素/WebComponents 吗? - Can I use Polymer elements / WebComponents with TinyMCE? 使用未发布的Polymer2自定义元素 - Use unpublished Polymer2 custom elements 如何在我的自定义Spotify应用程序中使用此jQuery插件? - How can I use this jQuery plugin with my custom Spotify Application? 我可以在JSFiddle上使用Polymer吗? - Can I use Polymer on JSFiddle? 使用for循环时,无法输出数组中的元素 - I can't output elements within my array when I use a for loop 如何使用javascript函数创建可以调用javascript函数的聚合物元素 - How can I use a javascript function to create polymer elements which can call javascript functions Polymer 1.0无法访问嵌套内的元素 <template> 元件 - Polymer 1.0 can't access elements within nested <template> element 在我的自定义功能之后,聚合物注册了所有元素 - Polymer register all elements after my custom function jQuery animate()对于我选择的特定元素能否表现出不同? - Can jQuery animate() behave differently for specific elements within my selection? 使用Polymer 3.0分别定义自定义元素以根据需求使用它们 - Defining Custom Elements separately with Polymer 3.0 to use them based on demand
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM