How to access shadow dow with jquery in a polymer.dart component

被刻印的时光 ゝ 提交于 2020-01-23 20:01:37

问题


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"]

or

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

How is this done with jquery

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

does not work obviously.


回答1:


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

String selector;

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

Then you can call jquery methods like this:

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

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

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

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

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.




回答2:


you have to use the webkitShadowRoot property like element.webkitShadowRoot.querySelector(...)



来源:https://stackoverflow.com/questions/21218123/how-to-access-shadow-dow-with-jquery-in-a-polymer-dart-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!