Helper broken in Ember 1.10

我只是一个虾纸丫 提交于 2019-12-01 06:06:27

问题


I was using custom Handlebars helper extending the functionality of 'if' block.

In Ember 1.10 this doesnt work anymore as there is no Ember.Handlebars.bind property which allowed binding to the property....

Ember.Handlebars.registerHelper('ifCond', function (a, b, options) {
    return Ember.Handlebars.bind.call(options, contexts[0], a, options, true, function(result) {
        return result === b
    });
});

The usage would be:

{{#ifCond property "value"}}
    {{some-other-component}}
{{else}}
    something other...
{{/ifCond}}

but this returns an error "Cannot read property 'call' of undefined"

Is there any way that I can bind to passed properties in helper? I cannot use registerBoundHelper because it doesn't support having child blocks... I wanted to use Component instead of helper but then I cannot use the {{else}} block...

This solution for the helper was previously taken from Logical operator in a handlebars.js {{#if}} conditional


回答1:


I actually managed to find a way to do it, so I'll write the answer for my own question...

Instead of using undocumented hacks, I used the proposed change: https://github.com/emberjs/ember.js/issues/10295

So my helper looks like this now:

Ember.Handlebars.registerBoundHelper('isSame', function(value1, value2) {
    return value1 === value2
});

and the usage:

{{#if (isSame property "value")}}
    {{some-other-component}}
{{else if (isSame property "otherValue"}}
    something other...
{{else}}
    something other...
{{/if}}


来源:https://stackoverflow.com/questions/28558696/helper-broken-in-ember-1-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!