Helm passing object to helper

I currently have an Ember object that looks like this:

name: 'Bob'
xs: {
    'actual':50
    'target':55
}

I have about 5-6 fields similar to xs. I need a helper method that can take this xs object and then return if the target has been deleted.

I thought about it:

Handlebars.registerHelper('hasHitTarget', function(attribute) {
    if (attribute.actual >= attribute.target)
    {
        return block(this);
    }
});

{{#each user in App.userController}}
    {{#hasHitTarget user.xs}}
        Target Hit
    {{/hasHitTarget}}
{{/each}}

Everything I read on the internet says this should work. But this is not so. When I console.log(attribute), it returns user.xsas a string. What's happening?

+5
source share
2 answers

There is a difference between Handlebars and Ember. Handlebars, Ember extends Handlebars inside to add additional functionality.

In doing so, you are using the wrong helper here, you need to use Ember.Handlebars.registerBoundHelper.

Ember.Handlebars.registerBoundHelper('hasHitTarget', function(attribute) {
  if (attribute.actual >= attribute.target) {
    return block(this);
  }
});
+2

Handlebars Helper #each - Ember ( v1.0), , ... .

fooobar.com/questions/1148777/...

0

All Articles