Using Polymer 1.0, suppose I have some elements nested in a dom-repeat element, such as the following:
<div id="stuffDiv">
<template is="dom-repeat" items="{{myItems}}">
<iron-icon icon="star" on-tap="onTap"></iron-icon>
</template>
</div>
I'd like to change an attribute, say class, on all the iron-icons within the "onTap" method. So I've figured out the following implementation
onTap: function(e) {
var index = e.model.index;
var stuffIcons = Polymer.dom(this.$.stuffDiv).querySelectorAll('iron-icon');
for (var i = 0; i <= index; ++i) {
this.toggleClass('magicClass', true, stuffIcons[i]);
}
for (var i = index+1; i < stuffIcons.length; ++i) {
this.toggleClass('magicClass', false, stuffIcons[i]);
}
},
This works, but feels very clunky. Is there a better approach that's not well documented? I don't see anything obvious on Polymer 1.0's resources.
Note, i've also tried having iron-icon's class depend on an item value and dynamically update that in onTap using this.set(...), however that doesn't work either, the class values I set get obliterated for reasons unknown to me.