Reputation: 231
I have this simple array that I pass to the template;
Template.incomeTotals.total = function() {
var array = [];
array[0] = [100000, 59, 58900];
return array;
};
and then this HTML file;
<body>
<table>
{{> incomeTotals}}
</table>
</body>
<template name="incomeTotals">
{{#each total}}
<tr>
<th>{{.0}}</th>
<th>{{.1}}%</th>
<th>${{.2}}</th>
</tr>
{{/each}}
</template>
What I am trying to do is get these three values all displayed on the same row, but all the values come out on the second row as 100000,59,58900%
. I saw in a similar question where someone was using the form of {{#each total.array}}
but I got no output when using that syntax.
Update:
Here's what ended up working for anyone else stumbling across this:
Template.incomeTotals.total = function() {
var array = [];
array[0] = {budgetTotal:100000, achievedAvg:59, sumTotals:58900};
return array;
};
HTML;
<body>
<table>
{{> incomeTotals}}
</table>
</body>
<template name="incomeTotals">
{{#each total}}
<tr>
<th>{{budgetTotal}}</th>
<th>{{achievedAvg}}%</th>
<th>${{sumTotals}}</th>
</tr>
{{/each}}
</template>
Upvotes: 2
Views: 1087
Reputation: 41
To access arrays by index in Meteor templates:
{{myArray.[0]}}
{{myArray.[0].that}}
Upvotes: 4
Reputation: 21815
Not an answer yet, but try:
<template name="incomeTotals">
{{#each total}}
<tr>
<th>{{this[0]}}</th>
<th>{{this[1]}}%</th>
<th>${{this[2]}}</th>
</tr>
{{/each}}
</template>
Upvotes: 0