Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Meteor 0.8.0中使用UI.registerHelper?_Javascript_Meteor_Spacebars - Fatal编程技术网

Javascript 如何在Meteor 0.8.0中使用UI.registerHelper?

Javascript 如何在Meteor 0.8.0中使用UI.registerHelper?,javascript,meteor,spacebars,Javascript,Meteor,Spacebars,在0.7.2中,我可以得到这样的结果 <span>{{color 'blue'}}</span> Handlebars.registerHelper('color', function (parameter) { return Session.equals('color', parameter) ? 'blue' : 'red'; }); 仍然返回此错误 Exception in Meteor UI: Error: Can't call non-function

在0.7.2中,我可以得到这样的结果

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

Handlebars.registerHelper('color', function (parameter) {
   return Session.equals('color', parameter) ? 'blue' : 'red';
});
仍然返回此错误

Exception in Meteor UI: Error: Can't call non-function: [object Object]
有什么帮助吗?

我正在做这件事&它工作正常(与我使用的完全一样)。你用铁刨吗?这也可以

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

    if(route && route.route && route.route.name == routeName) return 'active';
});
然后您可以在
routeName


我有点不确定为什么会出现此错误。您确定它来自Handlebar表达式吗。

您可能需要传递带有名称的参数:

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

UI.registerHelper('activePath', function() {
  return Session.equals('activePath', this.path) ? 'active' : '';
});
{{activePath='home'}
registerHelper('activePath',function()){
返回Session.equals('activePath',this.path)?'active':'';
});

原来这都是因为我的一个注册帮助者是“家长”这个词。使用它会产生一个错误,所以它使我的所有助手看起来都一团糟。我猜这是一个保留字。

是的,我确信它来自把手表达式,我使用的是铁路由器,但这个问题与路由无关。我使用这个助手只是在我的html中返回文本。你试过使用上面的方法吗?对你有用吗?它也做同样的事情(我想?)对不起,我有点困惑,是您提供的同一个代码片段导致了问题吗?如果没有,你能提供一个吗?好的,我把代码改为使用“colors”而不是“activePath”,以便更清楚地表明他的代码与路由无关。我在我的代码(w 0.8.0)中使用了
{{routeActive'home}}
,是否应该以这种新的方式完成?我不确定这是否是强制性的——我仍在关注0.8.0——但这解决了我的一些问题,我记得在文档中读到了这种变化,尽管我现在找不到地方。如果它适合你,那么也许你可以在某些情况下使用旧的语法。这也不起作用。我也尝试了
{{activePath path=home}}
,但没有成功,同样的错误。
<span>{{activePath path='home'}}</span>

UI.registerHelper('activePath', function() {
  return Session.equals('activePath', this.path) ? 'active' : '';
});