0

I have following handlebar and helper method

Handlebar

{{myHelper grp.group_name optionBinding=data}}

where data looks like => Object {Eastern Group: 1} and grp.group_name = 'Eastern Group'
Helper

Ember.Handlebars.registerBoundHelper('myHelper', function(value, options) {
  console.log(options);
  var map = options.hash.optionBinding;

  return map[value];
});

since I am using registerBoundHelper-- with every change in data (which is a key/value object) return from myHelper should also refresh ?

Following is as per guide published at http://emberjs.com/api/classes/Ember.Handlebars.html#method_registerBoundHelper

Bound hash options are also supported. Example:

{{repeat text countBinding="numRepeats"}}

In this example, count will be bound to the value of the numRepeats property on the context. If that property changes, the helper will be re-rendered.

4

1 回答 1

0

我认为您以错误的方式访问绑定。按照您提到的 API 链接,您的实现必须如下所示:

Ember.Handlebars.registerBoundHelper('myHelper', function(value, options) {
  console.log(options);
  var map = options.hash.option; //don't use Binding at the end

  return map[value];
});

当您使用帮助程序并指定属性“optionBinding”时,您是在告诉 ember 创建从值到属性“option”的绑定。因此,当您想要访问该值时,您必须只使用“选项”。

于 2013-03-22T09:24:21.277 回答