[英]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.