Ember的registerBoundHelper和handlebar块 [英] Ember's registerBoundHelper and handlebar blocks

查看:61
本文介绍了Ember的registerBoundHelper和handlebar块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我从这里获取了'is'帮助程序块,并修改它注册表通过Ember使用registerBoundHelper来帮助您。

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

我这样做的原因是因为我基本上需要一个基于'switch'语句的句柄。我的手柄的最终结果如下:

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

is语句只是简单地比较'MyProperty的和常量。

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

如果我不使用'registerBoundHelper'MyProperty通过作为字符串文字'MyProperty'而不是

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

现在:当我实际运行它时,这个逻辑似乎起作用/ strong>

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

问题是Ember会引发以下错误:

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?

推荐答案

你不应该忽略它,因为它不是支持,如果 MyProperty 在渲染发生后更改将会中断。

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

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



模板



Template

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

这篇关于Ember的registerBoundHelper和handlebar块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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