使用Flow Router访问父模板数据 [英] Access parent template data with Flow Router
问题描述
我切换到Flow Router,但遇到了问题.如何访问父模板数据?使用Iron Router,数据来自路由器,并且在模板内部可用,因此,如果我要访问父数据,Template.parentData()可以正常工作. 但是在Flow Router中,数据不是来自路由器,而是来自助手,而Template.parentData()不再包含数据!
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);
}});
推荐答案
您需要将该数据传递到模板.
You need to pass that data through to the Template.
例如{{> newPost parentPost=mydatahere}}
在此处查看更多信息: http://guide.meteor.com/blaze. html#name-data-contexts
See more here: http://guide.meteor.com/blaze.html#name-data-contexts
这篇关于使用Flow Router访问父模板数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!