0

在 0.7.2 中,我可以有这样的东西

<span>{{color 'blue'}}</span>

Handlebars.registerHelper('color', function (parameter) {
   return Session.equals('color', parameter) ? 'blue' : 'red';
});

它会工作得很好。0.8.0 版本中的等价物是什么?我知道他们用 UI.registerHelper 替换了 Handlebars.registerHelper,但是这个

UI.registerHelper('color', function (parameter) {
    return Session.equals('color', parameter) ? 'blue' : 'red';
});

仍然返回此错误

Exception in Meteor UI: Error: Can't call non-function: [object Object]

有什么帮助吗?

4

3 回答 3

1

原来这一切都是因为我的一个 registerHelpers 是“父母”这个词。使用它会引发错误,因此看起来我所有的助手都搞砸了。我猜这是一个保留字。

于 2014-03-30T00:23:57.187 回答
0

You probably need to pass the parameter with a name:

<span>{{activePath path='home'}}</span>

UI.registerHelper('activePath', function() {
  return Session.equals('activePath', this.path) ? 'active' : '';
});
于 2014-03-28T09:24:28.677 回答
0

我正在这样做并且它有效(就像我使用它一样)。你用铁路由器吗?这也可以。

UI.registerHelper('routeActive', function(routeName) {
var route = Router.current();

    if(route && route.route && route.route.name == routeName) return 'active';
});

然后你可以使用你的模板/路由的名称routeName

我有点不确定为什么你会收到那个错误,你确定它来自 Handlebars 表达式。

于 2014-03-28T08:10:03.153 回答