助手在Ember中打破1.10 [英] Helper broken in Ember 1.10

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

问题描述



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

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

使用情况是:

  {{#ifCond propertyvalue}} 
{{some-other-component}}
{{else}}
其他...
{{/ ifCond}}

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



有没有什么方法可以绑定到助手中传递的属性?我不能使用registerBoundHelper因为它不支持有子块...
我想使用组件而不是助手,但是我不能使用{{else}}块...



此帮助器的解决方案以前从逻辑运算符在一个handlebars.js {{#if}}条件

解决方案

我实际设法找到一个所以我会为自己的问题写出答案...



我不是使用未记录的黑客,而是使用了所提出的更改: https://github.com/emberjs/ember.js/issues/10295



所以我的帮手现在看起来像这样:

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

和用法:

  {{#if(isSame propertyvalue)}} 
{{some-other-component}}
{{else if(isSame propertyotherValue}}
其他...
{{else}}
其他...
{{/ if}}


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

解决方案

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

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

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