Reputation: 23231
I have the data:
priceGroups:
[
{
label: 'rate1",
price: 1.00,
numPeople: 1
},
{
label: 'rate 2",
price: 2.00,
numPeople: 2
},
{
label: 'rate 3",
price: 15.00,
numPeople: 4
},
];
and
labels:
[
'Solo',
'Duo',
'Trio'
'4 People',
'5 People
];
I want to be able to do this:
{{#priceGroups}}
{{for (a = 1; a <= {{this.numPeople}}; ++a)}}
<th>{{label[a]}}</th>
{{/for}}
{{/priceGroups}}
I have tried so much and nothing works.
Please help. It is important.
Upvotes: 0
Views: 808
Reputation: 707198
I think you can just use this:
{{#each priceGroups}}<th>{{label}}</th>{{/each}}
The {{#each priceGroups}}
gets you an iteration of the priceGroups
array and then each item of the array (which is an object) is presented to the template one after another so you can then reference the {{label}}
property in that object.
You don't embed javascript directly into handlerbars templates like you're trying to do.
Upvotes: 2