Meteor Blaze中父上下文的访问属性

Meteor Blaze中父上下文的访问属性,meteor,meteor-blaze,spacebars,Meteor,Meteor Blaze,Spacebars,在我的场景中,我使用“with”将上下文切换到一个相关对象,根据父对象的ID从助手处获取 Template.my_template.helpers({ my_related_object: function(){ return MyRelatedObjectsCollection.findOne({parentId:this_id}); } }); <template name="my_template"> <h1>{{name}}</h

在我的场景中,我使用“with”将上下文切换到一个相关对象,根据父对象的ID从助手处获取

Template.my_template.helpers({
   my_related_object: function(){
      return MyRelatedObjectsCollection.findOne({parentId:this_id});
   }
});


<template name="my_template">
<h1>{{name}}</h1>

{{#with my_related_object}}
   <span>{{name}} is related to {{here I want to display the parents name}}</span>    
{{/with}}   
</template>
Template.my_Template.helpers({
我的\u相关\u对象:函数(){
返回MyRelatedObjectsCollection.findOne({parentId:this_id});
}
});
{{name}}
{{{与我的{u相关的}
{{name}}与{{这里我想显示父母的名字}}相关
{{/与}}

如何在“with”上下文中访问父对象的属性?

您可以使用blaze模板中的目录样式目录导航来访问祖先数据上下文。就你而言:

<template name="my_template">
<h1>{{name}}</h1>
{{#with my_related_object}}
   <span>{{../name}} is the name of the parent object</span>    
{{/with}}   
</template>

{{name}}
{{{与我的{u相关的}
{{../name}}是父对象的名称
{{/与}}

看起来模板会很快地沿着父链向上移动,因为与我的\u相关的\u对象会随着id的更新而不断被替换。您真正想要的是同时访问原始对象及其父对象,是吗?