简体   繁体   English

如何在流星模板中访问父母的数据属性?

[英]How Do I Access a Parent's Data Attribute in Meteor Template?

I was trying to extend an application and found out that whenever I try to access the _id value from inside an #if clause, it always returns empty... 我试图扩展一个应用程序,发现每当我尝试从#if子句内部访问_id值时,它总是返回空...

This example returns the {{_../id}}: 本示例返回{{_ .. / id}}:

<template name="showsId">
  {{# each comments}}
    <div class="id">{{../_id}}</div>
  {{/each}}
</template>

But this one doesn't: 但这不是:

<template name="doesNotShowId">
  {{# each comments}}
    {{#if editingComments}}
      <div class="id">{{../_id}}</div>
    {{else}}
      <div class="id">{{../_id}}</div>
    {{/if}}
  {{/each}}
</template>

Do you know why this might be happening? 您知道为什么会这样吗? As far as I know this should work as expected. 据我所知,这应该可以正常工作。

EDIT: 编辑:

This is a template that's being called from another one, in this fashion: 这是从另一个模板中以这种方式调用的模板:

<template name="statusitems">
  <div>
    {{#each statusItem}}
  <div>
    {{> statusComments }}
  </div>
    {{/each}}
  </div>    
</template>

That's why I'm asking for the {{../_id}}. 这就是为什么我要{{../_id}}。

For both data contexts, the comment document seems to be provided by the each iterator. 对于这两个数据上下文,注释文档似乎由每个迭代器提供。

Therefore, I believe you should not be using ../ anyway since the document properties suchs as _id are already provided within the data context. 因此,我相信您无论如何都不应使用../,因为数据上下文中已经提供了诸如_id之类的文档属性。

This should work as is: 这应该按原样工作:

<template name="doesNotShowId">
  {{# each comments}}
    {{#if editingComments}}
      <div class="id">{{_id}}</div>
    {{else}}
      <div class="id">{{_id}}</div>
    {{/if}}
  {{/each}}
</template>

So should this: 所以应该这样:

<template name="doesNotShowId">
  {{# each comments}}
    <div class="id">{{_id}}</div>
  {{/each}}
</template>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Meteor的WebApp访问HTTP POST正文(表单数据)? 还是其他? - How do I access HTTP POST body (form-data) with Meteor's WebApp? Or anything else? 如何使用Javascript在Meteor的客户端访问模型数据? - How do I access model data on Meteor's client side using Javascript? 在Meteor中访问模板渲染函数中的父数据上下文 - Access parent data context in Template rendered function in Meteor 如何在Meteor中访问用户的Facebook好友列表? - How do I access a user's Facebook friends list in Meteor? 使用流星时,如何从另一个模板的辅助函数中调用模板? - How Do I Call a Template from Within Another Template's Helper Function When Using Meteor? 如何在Meteor中传递模板变量? - How do I pass template variables in Meteor? 如何将数据嵌入jQuery模板属性 - How do I embed data into jQuery template attribute 流星/ Mongodb:如何遍历数组并使用html在我的模板中获取遍历对象的详细信息? - Meteor/Mongodb: How do I traverse an array and get the traversed object's details in my template with html? 如何从流星模板助手返回模板? - How Do I Return Template From Meteor Template Helper? 如何在指令中访问属性的值? - How do I access an attribute's value in a directive?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM