助手在 Ember 1.10 中损坏
Helper broken in Ember 1.10
我正在使用自定义 Handlebars 助手扩展 'if' 块的功能。
在 Ember 1.10 中,这不再有效,因为没有 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}}
但这returns一个错误"Cannot read property 'call' of undefined"
有什么方法可以绑定到助手中传递的属性吗?我不能使用 registerBoundHelper 因为它不支持有子块......
我想使用 Component 而不是 helper 但是后来我不能使用 {{else}} 块...
这个帮助程序的解决方案以前来自 Logical operator in a handlebars.js {{#if}} conditional
我实际上设法找到了一种方法,所以我会写下我自己的问题的答案...
我没有使用未记录的 hack,而是使用了提议的更改: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}}
我正在使用自定义 Handlebars 助手扩展 'if' 块的功能。
在 Ember 1.10 中,这不再有效,因为没有 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}}
但这returns一个错误"Cannot read property 'call' of undefined"
有什么方法可以绑定到助手中传递的属性吗?我不能使用 registerBoundHelper 因为它不支持有子块...... 我想使用 Component 而不是 helper 但是后来我不能使用 {{else}} 块...
这个帮助程序的解决方案以前来自 Logical operator in a handlebars.js {{#if}} conditional
我实际上设法找到了一种方法,所以我会写下我自己的问题的答案...
我没有使用未记录的 hack,而是使用了提议的更改: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}}