我想從事件處理程序訪問我的模板的數據上下文,但它是空的。模板事件處理程序的流星數據上下文爲空
這裏是我的模板:
<template name="calendar">
<div class="calendar">
{{#with calendar}}
<h1>{{name}}</h1>
{{#each days}}
<div class="calendar-day">
{{this.date.getDate}}
<!-- I want to access the data context when this div is pressed -->
</div>
{{/each}}
{{/with}}
</div>
</template>
這裏就是我想要得到的數據上下文。
Template.calendar.events({
'click .calendar-day': function(e, template) {
console.log(Template.currentData()); // null
console.log(Template.parentData()); // null
}
});
更新:我能夠通過this
訪問當前的數據上下文,但我也想訪問父的數據上下文,即對calendar
但是我如何訪問父級的數據上下文? – harinsa