Is there a way to get the attributes name for a dynamically create element?

58 views
Skip to first unread message

Martin Amm

unread,
Jun 9, 2014, 6:22:05 PM6/9/14
to polym...@googlegroups.com
Hi,

I've e.g. a custom element with two attributes: who, where
<polymer-element name="hello-world" attributes="who where">
...

I'm now creating the element with
var hello = document.createElement('hello-world');

and I now need to know that my var hello has two attributes: "who where"

I unfortunately was not able to find a way to get this information. Did I miss something?

I've created a basic sample at http://jsbin.com/gadig/2/edit

Creating a metadata.html/x-meta seems to be a possible solution, but redundant / not DRY.


Martin

Rob Dodson

unread,
Jun 10, 2014, 10:22:04 AM6/10/14
to Martin Amm, polymer-dev
Hi Martin,

After you've created your element you should be able to just check for the existence of those properties in the polymer-ready callback. I've updated your jsbin: http://jsbin.com/nelav/2/edit

metadata.html is only used by the designer tool. Were you trying to add your element to the tool?


Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/fc2845fd-de5e-4049-9324-427cc63985b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rob Dodson

unread,
Jun 10, 2014, 10:50:47 AM6/10/14
to polym...@googlegroups.com, m...@adenin.de
Follow up from Martin
---

Hi,

 

> Were you trying to add your element to the tool?

No.

 

For some dynamic data binding in need to know which attributes are used by an element.

 

So it’s not about getting the value of who with

hello.who

 

But I’d like to get the attributes definition of a custom element like:

<polymer-element name="hello-world" attributes="who where">

 

So I’m looking for something like

hello.attributes

or

hello.polymer.attributes

 

returning

“who where”

 

Is there any option to get this information?

 

I’ve seen that the x-meta provides information about the properties of an element. But it doesn’t feel “right” having to define that for objects which won’t be used in the designer.

 

Martin

Rob Dodson

unread,
Jun 10, 2014, 12:58:05 PM6/10/14
to polymer-dev, Martin Amm
It looks like the `publish` object will have the stuff added to the element, so long as it's also either exposed in the attributes attribute, or part of the publish object itself.

http://jsbin.com/muwuv/6/edit

Martin Amm

unread,
Jun 10, 2014, 1:42:26 PM6/10/14
to polym...@googlegroups.com, m...@adenin.de
Perfect. That's exactly what I'm looking for.

Thank you.
Reply all
Reply to author
Forward
0 new messages