如何使用jquery在polymer.dart组件中访问shadow dow [英] How to access shadow dow with jquery in a polymer.dart component

查看:134
本文介绍了如何使用jquery在polymer.dart组件中访问shadow dow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的polymer.dart组件中,我想使用jquery访问shadow dom。
在dart我可以访问f.e.节点的id如下:

In my polymer.dart component I want to access the shadow dom with jquery. In dart I can access f.e. an node´s id like this:

$["testname"].attributes["id"]

shadowRoot.querySelector("#testname").attributes["id"]

context.callMethod(r'$', ['#testname'])["id"]

无法正常工作。

推荐答案

如果你想使用jquery从Dart访问shadow DOM,你可以这样做:

If you want to access shadow DOM from Dart using jquery, you can do this:

String selector;

JsObject jqueryObject = context.callMethod('\$', ['body /deep/ ${selector}']);

然后你可以像这样调用jquery方法:

Then you can call jquery methods like this:

jqueryObject.callMethod('click', [myFunc]);

void myFunc(var event) => print('it worked');

在属性的情况下,你需要调用jquery的attr >

In the case of the attribute, you would need to call jquery's attr() method.

String attr = jqueryObject.callMethod('attr', ['id']);

更新:到目前为止,我只能在Chrome桌面。我相信,其他浏览器不支持/ deep / combinator。

update: So far I have only managed to make this work on chrome for desktop. I believe, other browsers do not support the /deep/ combinator.

这篇关于如何使用jquery在polymer.dart组件中访问shadow dow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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