【问题标题】:Meteor - is there any way to access helper from another helperMeteor - 有没有办法从另一个助手访问助手
【发布时间】:2014-09-26 11:16:47
【问题描述】:

我找到了a similar question。但这不是我想要的。

Template.testTemp.helpers({
    firstValue: function () {
        return something
    },

    secondValue: function () {
        // I want to access firstValue here.
        // But I dont know what to do.
    }
})

有人可以帮助我吗?

谢谢!

【问题讨论】:

    标签: meteor


    【解决方案1】:

    如果您在传递的辅助对象之外定义辅助函数,则可以像使用任何其他函数一样使用它们。

    var firstValue = function () {
      return something;
    };
    
    var secondValue = function () {
      var fv = firstValue();
      return somethingelse;
    };
    
    Template.testTemp.helpers({
      firstValue: firstValue,
      secondValue: secondValue
    });
    

    【讨论】:

    • 我发现secondValue = function () { firstValue = Template.testTemp.firstValue(); }也可以!
    【解决方案2】:

    您可以通过以下方式破解对模板助手的调用:

    Template.tplName.__helpers.get('helper').call()
    

    MDG 建议使用常规函数,然后将其传递给助手、事件等。见here

    【讨论】:

      猜你喜欢
      • 2013-06-18
      • 2015-03-28
      • 2015-01-29
      • 1970-01-01
      • 2012-06-06
      • 2016-09-02
      • 2016-03-04
      • 1970-01-01
      • 2014-12-12
      相关资源
      最近更新 更多