Hey!
I am creating a statistics dashboard, which means a lot of tables. I want to save all the different statistics and their respective helper in an array. When I insert the table rows dynamically I get error saying
Can't call non-function: newClients
HTML
<tbody>
{{#each statistics}}
<tr>
<td>{{name}}</td>
<td>{{method 5}}</td>
<td>{{method 4}}</td>
<td>{{method 3}}</td>
<td>{{method 2}}</td>
<td>{{method 1}}</td>
<td>{{method 0}}</td>
</tr>
{{/each}}
</tbody>
Template.clients_widget.onCreated(function(){
this.statistics = [
{name:"New Clients", method:"newClients"},
{name:"Total Clients", method:"totalClients"},
{name:"Active(task) Clients", method:"taskClients"},
{name:"Active(login) Clients", method:"loginClients"},
];
});
Template.clients_widget.helpers({
statistics: function(){
return Template.instance().statistics;
},
newClients: function(month){
var certainMonth = Template.instance().certainMonth(month);
var clients = [];
Template.instance().clients.forEach(function(c){
if(c.createdAt.getMonth() === certainMonth ){
clients.push(c);
}
});
return clients.length;
},
});