Reputation: 1040
I have an array buttonColors, which has set of colors in the hex format. Now I want to display set of paper-button each with the color present in the buttonColors Array. How to achieve it in polymer 1.0?
<template is="dom-repeat" items="{{buttonColors}}">
<paper-button style="background-color:{{item}}" >
<b>click me</b>
</paper-button>
</template>
The above snippet does not seem to work. Kindly help.
Upvotes: 2
Views: 1547
Reputation: 16112
ebidel's comment is excellent as always. (He is one of the Google geniuses responsible building Polymer BTW)
1.0 doesn't support expressions in
{{}}
bindings. You'll need to make it a computed property:style="{{_computeStyle(item)}}"
... Documentation
Below, I have written out some example code for you to follow.
<dom-module id="x-element">
<template is="dom-repeat" items="{{buttonColors}}">
<paper-button style$="{{_computeStyle}}"> <b>click me</b> </paper-button>
</template> ...
<script>
(function() {
Polymer({
is: "x-element",
properties: {
value: {
type: Number,
notify: true
}
},
_computeStyle: function(item) {
// Compute style here
return "background-color:red";
}
});
})()
</script>
</dom-module>
Upvotes: 1
Reputation: 1040
You need to create a function and call it in following way
<template is="dom-repeat" items="{{buttonColors}}">
<paper-button style="{{computeStyle(item)}}" >
<b>click me</b>
</paper-button>
</template>
<script>
computedStyle:function(cl)
{
var s= "background-color:"+cl;
return s;
}
</script>
Upvotes: 2