Ember's registerBoundHelper and handlebar blocks

拜拜、爱过 提交于 2019-12-20 02:54:27

问题


So I have taken the 'is' helper block from here and modified it so that it register's it's helper through Ember using registerBoundHelper

The reason I did that is because I basically need a handlebars based 'switch' statement. The end result in my handlebars is as follows:

{{#is MyProperty 1}}
    ...Do something here...
{{/is}}
{{#is MyProperty 2}}
    ...Do something here...
{{/is}}
{{#is MyProperty 3}}
    ...Do something here...
{{/is}}
{{#is MyProperty 4}}
    ...Do something here...
{{/is}}

The is statement just does a simple comparison between 'MyProperty's value and a constant.

If I don't use 'registerBoundHelper' MyProperty gets passed through as the string literal 'MyProperty' and not it's value.

Now: This logic appears to work when I actually run it

The issue is that Ember throws the following error:

registerBoundHelper-generated helpers do not support use with Handlebars blocks.

Should I ignore this error and just continue on because it does appear to be working? Or should I try to rework the logic to not use a block?


回答1:


You shouldn't ignore it because it isn't supported, if MyProperty were to change after the render has occurred it will break.

Conditional helpers aren't supported (to many of our demise) in ember handlebars. The reason being is the core team wants this logic as a computed property instead of logic in the template.

IE

Controller

App.IndexController = Em.ObjectController.extend({
  isPropertyOne: Em.computed.equal('myProperty', '1')
});

Template

  {{#if isPropertyOne}}
    any template stuff
    {{render 'something'}}
    {{someValue}}
  {{/if}}


来源:https://stackoverflow.com/questions/21387694/embers-registerboundhelper-and-handlebar-blocks

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