Accessing a nested polymer element

basicallydan

Let's say I've defined two custom Polymer elements

<!-- Define inner elements -->
<polymer-element name="child-el" attributes="foo">
    <script>
        Polymer('child-el', {
            /* -- Attributes ------------------------------------------------ */
            foo: 'qux'

            /* -- Lifecycle ------------------------------------------------- */
            created: function() {
                console.log('Creating a Child');
            },
            /* -- Public Methods -------------------------------------------- */
            getFoo: function() {
                return [this.foo];
            }
        });
    </script>
</polymer-element>

<!-- Define custom element -->
<polymer-element name="parent-el">
    <script>
        Polymer('parent-el', {
            /* -- Lifecycle ------------------------------------------------- */
            created: function() {
                console.log('Creating a Container');
            },
            ready: function() {
                // This is the part that doesn't seem to work
                console.log(this.children[0].getFoo());
            }
        });
    </script>
</polymer-element>

And then in the markup which uses these elements:

<container>
    <child foo="bar"></child>
    <child foo="baz"></child>
</container>

As I've commented in the code I'd like to use the methods and/or attributes of the custom element child nodes of the custom element (not the child nodes of a template). Naturally, I'm aware there will be more than simply looping through an array, but at this point I'm not entirely sure how to essentially access each of the custom children as their Polymer types.

I hope that makes sense.

Thanks!

basicallydan

After an answer and brief discussion with @ebidel I came up with the full solution to my problem. Basically, I wanted to access child Polymer elements of a parent Polymer element within the parent's code, but ultimately I ended up doing it the other way around.

The lesson is that by the time domReady is called, the elements have been upgraded to include the methods which you've defined. Bueno.

<!-- Define inner elements -->
<polymer-element name="child-el" attributes="foo">
    <script>
        Polymer('child-el', {
            /* -- Attributes ------------------------------------------------ */
            foo: 'qux'

            /* -- Lifecycle ------------------------------------------------- */
            created: function() {
                console.log('Creating a Child');
            },
            ready: function () {
                // Not ready to access this.parentNode at this point
            },
            domReady: function () {
                this.async(function () {
                    // By this point this.parentNode is upgraded according to
                    // http://www.polymer-project.org/resources/faq.html#zerochildren
                    this.parentNode.doFooWithChild(this);
                });
            /* -- Public Methods -------------------------------------------- */
            getFoo: function() {
                return [this.foo];
            }
        });
    </script>
</polymer-element>

<!-- Define custom element -->
<polymer-element name="parent-el">
    <script>
        Polymer('parent-el', {
            /* -- Lifecycle ------------------------------------------------- */
            created: function() {
                console.log('Creating a Container');
            },
            ready: function() {
                // Not ready to access this.children at this point
            },
            doFooWithChild: function(child) {
                console.log(child.getFoo());
            }
        });
    </script>
</polymer-element>

Thanks for the help!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Polymer - Accessing Root Element

From Dev

Accessing Firebase from Polymer Element

From Dev

Accessing a div inside of a Polymer element template

From Dev

Catch exception from nested polymer element in Dart

From Dev

Polymer custom element property not accessible in nested template

From Dev

Polymer Access Element Inside of Nested Template by Id

From Dev

Accessing JavaScript methods inside nested Polymer custom elements

From Dev

Swift accessing nested array element specified by `NSIndexPath`

From Dev

Accessing element nested in multiple div in a website

From Dev

Accessing an element of a nested object using a variable for the key?

From Dev

Accessing an element in nested html code using selenium

From Dev

Accessing content values in Polymer

From Dev

Accessing Polymer dynamic elements

From Dev

Accessing a nested element 3 levels deep using page objects

From Dev

JQuery and accessing nested input element's value of a blog post

From Dev

Accessing a nested element 3 levels deep using page objects

From Dev

JQuery and accessing nested input element's value of a blog post

From Dev

Accessing all inner elements in Polymer?

From Dev

Accessing htmlElement in ShadowDom in Dart Polymer

From Dev

Accessing the Polymer created DOM with JQuery

From Dev

Accessing polymer functions from Javascript

From Dev

Nested polymer template inheritance

From Dev

Nested templates in Polymer

From Dev

Nested templates in Polymer

From Dev

clone of polymer element remove template of polymer element

From Dev

Polymer - Show element inside polymer element

From Dev

Trying to append a Polymer element in another Polymer element

From Dev

accessing the element in the following element

From Dev

Polymer querySelector can't find custom polymer element in polymer element

Related Related

  1. 1

    Polymer - Accessing Root Element

  2. 2

    Accessing Firebase from Polymer Element

  3. 3

    Accessing a div inside of a Polymer element template

  4. 4

    Catch exception from nested polymer element in Dart

  5. 5

    Polymer custom element property not accessible in nested template

  6. 6

    Polymer Access Element Inside of Nested Template by Id

  7. 7

    Accessing JavaScript methods inside nested Polymer custom elements

  8. 8

    Swift accessing nested array element specified by `NSIndexPath`

  9. 9

    Accessing element nested in multiple div in a website

  10. 10

    Accessing an element of a nested object using a variable for the key?

  11. 11

    Accessing an element in nested html code using selenium

  12. 12

    Accessing content values in Polymer

  13. 13

    Accessing Polymer dynamic elements

  14. 14

    Accessing a nested element 3 levels deep using page objects

  15. 15

    JQuery and accessing nested input element's value of a blog post

  16. 16

    Accessing a nested element 3 levels deep using page objects

  17. 17

    JQuery and accessing nested input element's value of a blog post

  18. 18

    Accessing all inner elements in Polymer?

  19. 19

    Accessing htmlElement in ShadowDom in Dart Polymer

  20. 20

    Accessing the Polymer created DOM with JQuery

  21. 21

    Accessing polymer functions from Javascript

  22. 22

    Nested polymer template inheritance

  23. 23

    Nested templates in Polymer

  24. 24

    Nested templates in Polymer

  25. 25

    clone of polymer element remove template of polymer element

  26. 26

    Polymer - Show element inside polymer element

  27. 27

    Trying to append a Polymer element in another Polymer element

  28. 28

    accessing the element in the following element

  29. 29

    Polymer querySelector can't find custom polymer element in polymer element

HotTag

Archive