I’m trying to replace my helpers with a view model component, but I can’t get the same functionality. The issue with the helpers is that I need to use a reactive variable to get the results of a callback function, but that seems to create a looping function call when the data is mostly static. It seems to make my application go really really slow and I tried to implement the same functionality with view model, but it doesn’t work.
It’s currently using the following:
Template.discussDashboard.helpers({
discussion: function(){
var instance = Template.instance();
Meteor.call('user.subscriptions', function(error, result){
if (error) console.log("Error");
instance.discussions.set(result);
});
areas = instance.discussions.get();
return {area : areas};
}
});
And the following:
{{#with discussion}}
{{#each area}}
<tr>
<td>
<a style="color: black; font-size: 20px" href="/discussions?area={{this}}">
<span> <b>#{{this}}</b></span>
</a>
</td>
</tr>
{{/each}}
{{/with}}
I’m tried to change it to the following, but nothing displays.
Template.discussDashboard.viewmodel({
discussions: [],
addDiscussions: function() {
var self = this;
Meteor.call('user.subscriptions', function(error, result) {
if (error) console.log("Error");
self.discussions(result);
});
}
});
With the following:
{{#each discussions}}
<tr>
<td>
<a style="color: black; font-size: 20px" href="/discussions?area={{b "text: this"}}">
<span {{b "text: this"}}></span>
</a>
</td>
</tr>
{{/each}}