MeteorJS - 访问同一模板的助手

MeteorJS - access to helpers of the same template

我正在用 meteor 做第一个项目,但遇到了一些小问题(我想这很容易解决),但我找不到正确的方法来解决它。这是我想将一些对象推送到辅助数组的简化代码。

Template.courses.helpers({
    doneCourses: [],
    init: function(){
        doneCourses.push({ title: this.name, date: this.endDate });      
    }
});

不幸的是我有错误:"Exception in template helper: ReferenceError: doneCourses is not defined.."。正确的做法是什么?我想在 HTML 和

上显示 doneCourses
{{ #each doneCourses }}

但我必须在一开始就从数据库中获取它。附加问题 - 执行 init 函数的最佳方法是什么?在 iron router data field 中做还是做单独的 init 函数?

doneCourse: function () { ... }

才是正确的做事方式。

如果您需要在呈现或创建模板时执行操作,您可以使用模板提供的 onRenderedonCreated