Reputation: 841
Initially i shows 3 persons information.After that when ever click a button then changes the 3 persons information to another.I did but the information doesn't changes.So Please see the below code once and suggest me what to do?
Html Code :
{{#each patientInfo}}
City: {{City}}<br>
State: {{State}}<br>
Country: {{Country}}<br>
ZipCode: {{ZipCode}}<br>
PhoneNo: {{PhoneNo}}<br>
{{/each}}
Js Code :
Template.userlist.patientInfo = function ()
{
//here startIndex and endIndex are changed when ever clicks button so how to update every time based on the click event
records = User.find().fetch();
return records.slice(startIndex,endIndex);
};
//Here Changes the startIndex & endIndex based click events
Template.userlist.events
({
'click .nostoIndex': function (e,t)
{
if (typeof console !== 'undefined')
e.preventDefault();
startIndex = e.target.innerHTML * 3;
endIndex = startIndex + 3;
Template.userlist.patientInfo();
}
});
Upvotes: 0
Views: 55
Reputation: 4074
The problem is that probably startIndex
and endIndex
are not reactive data sources so the result of records.slice(startIndex,endIndex);
won't be recalculated if any of the variables change, even though your code is in a reactive context (the template helper).
What you can do is to either make make the variables reactive yourself by manually keeping track of all computations that used it or simply use a reactive data source like session variables. The second option is much simpler and sufficient in your case.
For example:
...
Session.set('startIndex', e.target.innerHTML * 3);
...
and
...
return records.slice(Session.get('startIndex'), Session.get('startIndex') + 3);
...
Upvotes: 1