在 Ember 1.10 中损坏的助手 [英] Helper broken in Ember 1.10

查看:21
本文介绍了在 Ember 1.10 中损坏的助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了自定义 Handlebars 助手来扩展if"块的功能.

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

在 Ember 1.10 中,这不再起作用,因为没有 Ember.Handlebars.bind 属性允许绑定到该属性......

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
    });
});

用法是:

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

但这会返回错误无法读取未定义的属性'调用'"

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

有什么方法可以绑定到 helper 中传递的属性?我不能使用 registerBoundHelper 因为它不支持有子块...我想使用 Component 而不是 helper 但后来我不能使用 {{else}} 块...

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...

这个助手的解决方案以前取自 逻辑运算符在handlebars.js {{#if}} 条件

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

推荐答案

我实际上设法找到了一种方法,所以我会为我自己的问题写答案...

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

我没有使用未记录的黑客,而是使用了建议的更改:https://github.com/emberjs/ember.js/issues/10295

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
});

和用法:

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

这篇关于在 Ember 1.10 中损坏的助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆