【问题标题】:Meteor: can I define a namespace for global helpers?Meteor:我可以为全局助手定义一个命名空间吗?
【发布时间】:2016-03-19 01:03:39
【问题描述】:

我想做这样的事情来定义全局助手:

// namespace Strings

Template.registerHelper('Strings.truncate', function(s, l) {
  // ...
});

Template.registerHelper('Strings.ellipsis', function(s) {
  // ...
});

// namespace Format

Template.registerHelper('Format.currency', function(s) {
  // ...
});

Template.registerHelper('Format.integer', function(s) {
  // ...
});

// etc

但是当我尝试使用其中一个助手时出现错误:

{{ Strings.truncate 'some string' 5 }}

Uncaught Error: Can't call non-function: null

有没有办法为全局助手提供某种命名空间?

【问题讨论】:

    标签: meteor namespaces meteor-blaze spacebars


    【解决方案1】:

    我找到了一种方法,我可以这样使用square brackets syntax in handlebar

    {{ [Strings.truncate] 'some string' 5 }}
    

    所以我可以给全局助手起一个带点的名字 (.) 并有一种命名空间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-14
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      • 2012-03-27
      • 2013-12-13
      相关资源
      最近更新 更多