gpt4 book ai didi

ember.js - Ember 1.10 中的助手损坏

转载 作者:行者123 更新时间:2023-12-02 21:36:05 26 4
gpt4 key购买 nike

我使用自定义 Handlebars 助手扩展“if” block 的功能。

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

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

但这会返回错误“无法读取未定义的属性‘call’”

有什么方法可以绑定(bind)到助手中传递的属性吗?我无法使用 registerBoundHelper 因为它不支持拥有子 block ......我想使用 Component 而不是 helper,但是我无法使用 {{else}} block ...

此帮助程序的解决方案之前取自 Logical operator in a handlebars.js {{#if}} conditional

最佳答案

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

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

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

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.js - Ember 1.10 中的助手损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28558696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com