Reputation: 197
I have a strange issue that I can't figure out. I have a method and a method call in my template event handle. For some reason the method call only works like 1 time out of 5 and it doesn't update DOM. When the call works, console.log(Session.get('getReportData')+ " from method call");
returns Objects to console but not to the DOM.
When I set the variable manually in console and call:
Meteor.call('getReportData',startDate, finishDate, function(err, data) {
console.log("is the call working at all??");
if (err)
console.log(err);
Session.set('getReportData', data);
console.log(Session.get('getReportData')+ " from method call");
});
I get everything back and DOM is updated also.
Here is the code:
Method:
'getReportData': function(startDate, finishDate) {
/*
if (mingi check, mis annaks errorit?) {
throw new Meteor.Error("no-data-found", "No data can be found for selected period");
} */
var reportData = ScrapReport.find({dateEntered: { $gte: startDate}, dateEntered: { $lte: finishDate}}).fetch();
return reportData;
}
Client:
Template.report.events({
'click .btn': function(startDate, finishDate) {
var startDate = $('#startDate').val();
console.log(startDate + ' StartfromTheButton')
var finishDate = $('#finishDate').val();
console.log(finishDate + ' FinishfromTheButton')
Meteor.call('getReportData',startDate, finishDate, function(err, data) {
console.log("is the call working at all??");
if (err)
console.log(err);
Session.set('getReportData', data);
console.log(Session.get('getReportData')+ " from method call");
});
}
})
Template.reportData.helpers({
'reportData': function () {
return Session.get('getReportData');
}
});
What can cause this issues?
Upvotes: 0
Views: 33
Reputation: 197
I was missing event in the function call and event.preventDefault();
Upvotes: 0