I have a template with a table created by iterating over an array of user selected companies, which are stored, by ticker symbol, in a document attribute called selections. I show different values associated with each company, depending on a different user selection, called metric.
I am having trouble writing a helper with the if/else statement required to change the value depending on the user selection. With the code below, headingNum and headingDen are showing properly. So is companyName which is associated with an individual selection. If I replace valuationNum with this.reported.capTable.enterpriseValue, the correct value appears. But I cannot get it to appear when using the helper.
<template name="Table">
<div>
<table>
<thead>
<tr>
<th>Company</th>
<th>{{headingNum}}</th>
<th>{{headingDen}}</th>
</tr>
</thead>
<tbody>
{{#each selections}}
<tr>
<td>{{companyName}}</td>
<td>${{valuationNum}}</td>
<td>${{valuationDen}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</template>
JS file
var metric = this.metric;
var period = this.period;
Template. Table.helpers({
selections: function () {
var selected = this.selections;
return Companies.find({ticker: {$in: selected}})
},
headingNum: function () {
switch (metric) {
case "A":
return "EV";
break;
case "B":
return "Price";
break;
default:
return "EV"
}
},
valuationNum: function() {
switch (metric) {
case "A":
return this.reported.capTable.enterpriseValue;
break;
case "B":
return this.reported.capTable.lastClose;
break;
default:
return ""
}
}
});
I tried breaking out the {{#each}}{{each}} block into a new template to see if it would help with the data context but no luck (and it messes up the table).
Am I writing these helpers correctly?
I also receive an error message in the JS file saying reported is an unresolved variable even though that is the correct path.
Thank you.
EDIT:
This helper works, not sure why the other doesn't:
headingNum: function () {
var metric = this.metric;
switch (metric) {
case "EV/EBITDA":
return "EV";
break;
case "Price/Earnings":
return "Price";
break;
default:
return ""
}
}