什么" .."在Meteor Spacebars声明中做什么?

时间:2015-04-16 12:45:07

标签: javascript meteor spacebars

我有一个把用户标识传递给助手的把手语句。我不确定这是如何工作的。车把{{#if isowner ..}}有..这里作为辅助功能的参数传递了什么?

<template name="test">
  ...
    <table class="table table-hover table-striped">
      {{#each tester}}
      <tr><
        <td>{{#if isowner ..}} 
                  <i class="fa fa-trash removeUser"></i>
            {{/if}}
        </td>
      </tr>
      {{/each}}
    </table>
  ...    
</template>


Template.test.helpers({
  'isowner':function(parent){
    return parent.userId === Meteor.userId();
  }
});

显然,只有当用户ID相同时才会这样。 Meteor.userId()是客户端的当前用户。那么哪个用户标识传递给parent? 当然,这个名字代表着它的自我。它必须高于一级 - 但这在技术上是什么?去哪儿了?

1 个答案:

答案 0 :(得分:1)

..返回父(封闭)模板或结构的数据上下文 - 我绑定了一个非常简单的MeteorPad here,您可以使用它来查看它是如何工作的。

在您的情况下,我认为它可能会返回test模板的数据上下文。您可以在助手中console.log(parent)检查该对象并获取更多信息:

Template.test.helpers({
  'isowner':function(parent){
    console.log(parent);
    return parent.userId === Meteor.userId();
  }
});

您可以在spacebars readme.

中找到有关如何解决..以及如何使用{{1}}的更多信息