3
我想要定義一個新的ReactiveVar變量,使其可以在所有模板部分(如.events,.helpers,.rendered等)中訪問,如圖所示在我的代碼下面,但我總是得到一個錯誤:流星定義ReactiveVar可在.events和.helpers中訪問
Error: Exception in template helper:
ReferenceError: logData is not defined
有人可以告訴我什麼我失蹤/做錯了嗎?由於
代碼:
Template.detailedreport.rendered = function() {
var logData = new ReactiveVar;
logData.set([]);
};
Template.detailedreport.helpers({
myCollection: function() {
return logData.get();
}
});
Template.detailedreport.events({
'submit form': function(e) {
e.preventDefault();
var now = Session.get("startDate");
var then = Session.get("endDate");
var custID = Session.get("customer");
var projID = Session.get("project");
Meteor.call('logSummary', now, then, projID, custID, function(error, data){
if(error)
return alert(error.reason);
logData.set(data);
});
}
});