I was wondering how to print a part of my JSON object in Polymer without it printing just the template code I wrote.
My JSON object looks like this:
weekDagenVertalingen:{
type: Object,
value:
{
'MONDAY':'Maandag',
'TUESDAY':'Dinsdag',
'WEDNESDAY':'Woensdag',
'THURSDAY':'Donderdag',
'FRIDAY':'Vrijdag',
'SATURDAY':'Zaterdag',
'SUNDAY':'Zondag'
}
}
In javascript I'm able to do this:
var day = 'MONDAY';
console.log(weekDagenVertalingen[day]);
This Javascript code prints out:
Maandag
But for some reason when trying this:
{{weekDagenVertalingen[item.day]}}
It literally prints out this: {{weekDagenVertalingen[item.day]}} instead of the actual value of the JSON object.
I was thinking about getting the string this way:
{{weekDagenVertalingen.item.day}}
But I have no clue how to tell Polymer item.day
is a value.
What am I doing wrong here?
It's been a while since I've used Polymer, but I believe that you want a computed binding. Computed bindings only work one way (host to target).
...
<span>[[_getDay(item])]]</span>
...
<script>
Polymer({
...
_getDay: function(item) {
return this.weekDagenVertalingen[item.day];
}
})
</script>
see: https://www.polymer-project.org/1.0/docs/devguide/data-binding (scroll down until you see the computed bindings section)