我使用流星0.6.4。我的问题是,呈现的模板的数据上下文时有时未定义,因此,“这”目的是窗口的引用:为什么流星模板onRendered Function中的'this'未定义?
Template.task.time_left = function(){
debugger;
var nDate = this.due_date.getTime();
Exception from Deps recompute: TypeError: Cannot call method 'getTime' of undefined
HTML代码被包裹的{{每个}}车把内声明:
<template name="tasks_lists">
{{#each tasks_list}}
...
{{#each task}}
{{> task}}
{{/each}}
...
{{/each}}
</template>
<template name="task">
...
<div class="text">{{due_date}}</div>
...
</template>
我读到这个错误已在Meteor的早期版本中解决。我能做些什么来避免使用'this'作为Window调用的函数。
模板内的'this'对象'onRendered'回调函数是对与该函数关联的模板实例的引用。查看[流星文档](http://docs.meteor.com/#/full/template_onRendered)了解'onRendered'模板回调函数的更多细节。 – n4tiv3pwnst4r