How to querySelector elements of an element's DOM using Polymer

我怕爱的太早我们不能终老 提交于 2019-11-29 10:06:22

Polymer does not provide a helper function or abstraction that will list nodes both from the light and local DOMs.

If you require this functionality, you can use this.querySelector(selector).

On a side note, aside from the Polymer.dom(this.root).querySelectorAll(selector) method, Polymer also provides the $$ utility function which helps in accessing members of an element's local DOM. This function is used as follows:

<dom-module id="my-element">
  <template>
    <p class="special-paragraph">...</p>
    <content></content>
  </template>
</dom-module>

<script>
  Polymer({
    is: 'my-element',
    ready: {
      this.$$('.special-paragraph'); // Will return the <p> in the local DOM
    }
  });
</script>

Note that, unlike querySelectorAll, the $$ function only returns one element: the first element in the local DOM which matches the selector.

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