[英]Access parent data context in Template rendered function in Meteor
I have the following parent template: 我有以下父模板:
<template name="parentTempl">
{{#each child}}
{{> childTempl}}
{{/each}}
</template>
I want to access the parent data context in childTempl
: 我想访问
childTempl
的父数据上下文:
Template.childTempl.rendered = function() {
console.log(this.parent.data); // ?
};
How can I do this? 我怎样才能做到这一点? Any help would be greatly appreciated.
任何帮助将不胜感激。
You can use Template.parentData(n)
to access the parent context inside any template helper or rendered callback. 您可以使用
Template.parentData(n)
访问任何模板助手或渲染回调中的父上下文。 See the docs here . 请参阅此处的文档。 Internally, all it does is call the Blaze getView method for the parent view until it hits the desired parent context (as defined by n).
在内部,它所做的就是为父视图调用Blaze getView方法,直到它到达所需的父上下文(由n定义)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.