在不使用Ember-CLI的情况下使用EmberJS 2.0注册帮助程序

Registering helpers with EmberJS 2.0 without the use of Ember-CLI

本文关键字:注册 EmberJS 帮助程序 Ember-CLI 情况下      更新时间:2023-09-26

我和我的团队正在用EmberJS 2.0开发一个应用程序。由于我们有Ember-CLI没有提供的特定需求,因此我们开发了自己的解决方案,使用Grunt任务来编译我们的应用程序。

在以前的EmberJS版本中,我们使用以下方法来注册新的handlebar helper:

Ember.Handlebars.registerBoundHelper('date-display', function(data, unix) {
    ...
});

我们现在面临的问题是在Ember中不赞成使用registerHelper方法。车把名称空间。现在我们像这样生成帮助器:

var dateDisplayHelper = Ember.Helper.helper('date-display', function(params, hash){
     ...
});

我们的问题是,我们如何注册这个助手,使它在我们的车把模板中可用?

App.DateDisplayHelper = Ember.Helper.helper(function(params, hash){
  return "foo?";
});

JSBin: http://emberjs.jsbin.com/kaqere/3/edit?html、js、输出