【问题标题】:What does ".." do in an Meteor Spacebars statement?“..”在 Meteor Spacebars 语句中的作用是什么?
【发布时间】:2015-06-22 21:12:05
【问题描述】:

我有一个句柄语句,它将用户 ID 传递给助手。我不确定这是如何工作的。车把{{#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? 当然,这个名字不言自明。它必须高于一个级别 - 但从技术上讲这是什么? ..去哪里?

【问题讨论】:

    标签: javascript meteor spacebars


    【解决方案1】:

    .. 返回父(封闭)模板或结构的数据上下文——我组装了一个非常简单的 MeteorPad here,您可以尝试看看它是如何工作的。

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

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

    您可以在spacebars readme. 中找到有关如何解析.. 以及如何使用它的更多信息

    【讨论】:

    • 感谢 MeteorPad!明白了!
    猜你喜欢
    • 1970-01-01
    • 2014-08-11
    • 2017-08-08
    • 1970-01-01
    • 2014-07-06
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    相关资源
    最近更新 更多