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

时间:2017-02-14 12:55:56

标签: meteor meteor-blaze spacebars

在我的场景中,我使用"使用"要将上下文切换到相关对象,我将根据父级的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>

如何使用&#34;访问&#34;中的父对象的属性?上下文

1 个答案:

答案 0 :(得分:2)

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

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