I have the following code in my app:
{{#each this.currentItemData['timeline']}}
{{#each lessons}}
<span>{{startTime}} - {{endTime}}</span>
{{/each}}
{{/each}}
startTime and endTime are values from array of objects in data of my page, like that
timeIntervals: [
{
id: 1,
value: '0900',
label: '09 AM'
},
{
id: 1,
value: '1000',
label: '10 AM'
},
]
I don’t want to display value field in template, it should be label field, so I wrote a simple function in methods of page:
convertTime : function(value) {
return this.timeIntervals.find(el => el.value == value).label;
}
But I can’t call it from template like that:
<span>{{@root.convertTime(startTime)}} - {{@root.convertTime(endTime)}}</span>
However it works if I place it on top on the context and call it like {{this.convertTime(this.constTime)}}
where constTime
is some variable from data, just for example.
I’ve tried some different approaches like
{{js 'this.convertTime("0900")'}}
{{js '@root.convertTime("0900")'}}
{{js '@root.convertTime(this.startTime)'}}
{{js '../../convertTime(this.startTime)'}}
but all of them are throwing different errors. Help please!!