我使用流星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