2

我切换到流路由器,但我遇到了问题。如何访问父模板数据?使用 Iron Router,数据来自路由器并且在模板中可用,所以如果我想访问父数据 Template.parentData() 正在工作。但是在流路由器中,数据不是来自路由器,而是来自助手,并且 Template.parentData() 中不再有数据了!

<template name="myTemplate">
    {{#if Template.subscriptionsReady}}
      {{> showPost parentPost }}
      {{> newPost }}
    {{/if}}  
</template>

Template.myTemplate.helpers({
    parentPost: function(){ return Posts.findOne({...})}
});

Template.newPost.events({
    'submit .js-new-post':function(event,template){
         console.log(Template.parentData(1).parentPost);
}});
4

1 回答 1

1

您需要将该数据传递给模板。

例如{{> newPost parentPost=mydatahere}}

在此处查看更多信息:http: //guide.meteor.com/blaze.html#name-data-contexts

于 2016-03-29T16:04:48.607 回答