javascript - Accessing all inner elements in Polymer? -
i have:
<k-myelement> <k-anotherelement></k-anotherelement> </k-myelement>
when define template this:
<polymer-element name="k-myelement"> <template> <content select="k-anotherelement" id="anotherelement"></content> </template> </polymere-element>
i can access inner element this.$['anotherelement']
but approach have predefine, inner elements can used.
what want template technique, allows me access inner elements.
<content>
(insertion points) rendering elements in light dom @ specific locations in shadow dom. using <content select="k-anotherelement"></content>
says "render <k-anotherelement>
elements here. if want light dom nodes invited rendering party, use <content></<content>
.
the other issues snippet:
- the name of element needs defined on
<polymer-element>
, not<template name="k-myelement">
to list of nodes pass through
<content>
, usecontent.getdistributednodes()
. may want consider if need<content>
. light dom children nodes can access.children
, other accessors. the polymer docs:for
<content>
, can iterate throughcontent.getdistributednodes()
list of nodes distributed @ insertion point.in polymer, best place call method in
attached()
callback you’re guaranteed element in dom tree.also remember can access light dom element’s normal children (i.e.
this.children
, or other accessors). difference approach it’s entire set of potentially distributed nodes; not distributed.
Comments
Post a Comment