jQuery插件和Polymer元素 [英] jQuery plugins and Polymer elements

查看:98
本文介绍了jQuery插件和Polymer元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试将几个jQuery插件包装在Polymer元素中,但迄今为止收效甚微.例如,select2插件(此处讨论的问题)和DataTables插件发现

I have attempted to wrap a couple of jQuery plugins in Polymer elements, but have so far had little success. For example the select2 plugin (troubles discussed here) and the DataTables plugin found here. Although it would be great to not have jQuery dependencies, the landscape for ready to use jQuery plugins is really mature and until the web components libraries catch up, it would be nice to have wrappers that bring all of the goodness of web components to the deep library of jQuery plugins.

我的问题是,在Polymer元素内使用jQuery时是否需要考虑一些关键的陷阱?甚至更有用的是,有没有成功的例子可以很好地包装jQuery插件的Polymer元素的例子?到目前为止,我对此类示例的搜索很少.

My question is are there any key gotchas when working with jQuery within a Polymer element that need to be considered? And even more useful, are there good examples of successful Polymer elements that wrap jQuery plugins? My searching for such examples have so far uncovered very little.

推荐答案

我的问题是使用jQuery时是否存在任何关键陷阱 在需要考虑的聚合物元素中?

My question is are there any key gotchas when working with jQuery within a Polymer element that need to be considered?

最大的问题可能与Shadow DOM有关.当您将标记放置在Shadow DOM内时,jQuery无法选择它.许多插件都假定其所有内容在Light DOM中都可用,因此可能导致各种问题.希望较新版本的jQuery将找到使用Shadow DOM的方法,因此这可能不再是一个问题.

Probably the biggest issue is going to be around Shadow DOM. When you place markup inside of the Shadow DOM it cannot be selected by jQuery. Many plugins assume that all of their content is available in the Light DOM so that can lead to all kinds of problems. Hopefully newer versions of jQuery will find ways to work with the Shadow DOM so this might become less of an issue.

甚至更有用的是,有一些成功的聚合物例子. 包装jQuery插件的元素?

And even more useful, are there good examples of successful Polymer elements that wrap jQuery plugins?

如果您真的想使用jQuery插件 Polymer元素,那么最好在Light DOM中构造jQuery插件,然后将它们作为<content>传递到您的元素中. 这是一个jsbin示例,它构造一个Select2元素并将其传递到Polymer元素中以便可以显示

If you really want to work with a jQuery plugin and Polymer elements then it might be best to construct your jQuery plugins in the Light DOM and then pass them into your elements as <content>. Here's a jsbin example which constructs a Select2 element and passes it into a Polymer element so it can be displayed.

这篇关于jQuery插件和Polymer元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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