Access parent template data with Flow Router

半腔热情 提交于 2019-12-23 22:16:13

问题


I switched to Flow Router and I have a problem. how can I access the parent template data? with Iron Router the data was coming from router and was available inside the template, so if I wanted to access a parent data Template.parentData() was working. But in Flow Router the data is not coming from router, it comes from helpers and Template.parentData() doesn't have the data in it anymore!

<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);
}});

回答1:


You need to pass that data through to the Template.

E.g. {{> newPost parentPost=mydatahere}}

See more here: http://guide.meteor.com/blaze.html#name-data-contexts



来源:https://stackoverflow.com/questions/36272368/access-parent-template-data-with-flow-router

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!