0

I'm looking for a way to determine what attributes a polymer element has without interacting with the attributes directly. I stumbled upon this.attributes accidentally and it does contain all the information that I need It's just not very pretty. I was wondering if there was a simple attributes object that existed already. Something simple like this.

{
  "src": "http://stackoverflow.com/image.jpg",
  "alt": "stackoverflow"
}

Here's how you'd convert it using underscore, it's a little ugly.

this.attr_obj = _.extend.apply(null, _.map(this.attributes, function(attribute){
  var temp = {};
  temp[attribute.name] = attribute.value;
  return temp;
}));
ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
  • [].map.call(this.attributes, function(attribute){ this[attribute.name] = attribute.value; return this;},{})[0]; – dandavis Aug 19 '14 at 03:47

1 Answers1

1

Found the answer in another post.

It's best to use element.publish to get the list of published properties for an element. (In polymer 1.0 element.properties does the same).

element.getAttribute('attributes) won't include the publish properties that are setup in a publish block.

Community
  • 1
  • 1
ThomasReggi
  • 55,053
  • 85
  • 237
  • 424