1
我有一个路径和模板,具有作为routes.js定义正确的数据方面:流星数据上下文子模板
this.route('entrant_view_race', {
path: '/organise/entrants/:_id/',
yieldTemplates: navOrganise,
waitOn: function() {
return Meteor.subscribe('entrants');
},
data: function() {
return Races.findOne(this.params._id);
}
});
数据上下文设置为数据功能上面没有问题。在entrant_view_race模板/路由,我们有另一个模板:
<div class="row">
<div class="col-md-4">
{{> chart_entrant_status}}
</div>
</div>
现在chart_entrant_status内是通过其在数据上下文定义设置了一个param订阅:
Meteor.subscribe('entrantStatusCount', this._id);
但this._id
是不确定的。我相信,除非您明确定义了如{{> chart_entrant_status dataContext}}
,否则无论父级的数据上下文是否传递给子模板?如何将父上下文的_id传递给子模板(我不想使用会话变量)。
编辑:
chart_entrant_status
模板看起来是这样的:
<template name="chart_entrant_status">
{{#chart_container title="Entrants" subtitle="Status" class="race-status"}}
{{_id}}
<div id="chart"></div>
{{> table_entrant_status}}
{{/chart_container}}
</template>
注{{_id}}
呈现精做背景是活到这一点。而当模板呈现订阅:
Template.chart_entrant_status.rendered = function() {
Meteor.subscribe('entrantStatusCount', this._id); // this._id is undefined - if I substitute for the actual id as a string Ba48j2tkWdP9CtBXL I succeed....
}
但没有雪茄......苦苦寻找,我失去的数据上下文...
EDIT2:这将返回this._id
精...
Template.chart_entrant_status.helpers({
stuff: function() {
return this._id; // returns the right id in {{stuff}} in the template
}
})
那么数据上下文不可用于Template.chart_entrant_status.rendered
?
EDIT4:解决了。它this.data._id ....哈啊
凡位于你的'Meteor.subscribe'到底是什么?默认情况下,子模板会继承父数据上下文。 – saimeunt 2014-11-03 17:33:51
谢谢,我添加了更多的细节。 – user1048175 2014-11-03 19:18:48