English 中文(简体)
你们如何使用无约束的财产作为与Ember.js的模板中的助手的论点?
原标题:How do you use an unbound property as the argument of an if helper in a template with Ember.js?
  • 时间:2012-04-25 08:19:30
  •  标签:
  • ember.js

I have a Handlebars helper that takes a number and returns a class name. I want to run the helper only if foobar exists because it might not exist. My initial attempt was:

{{#each content}}
    <div class="other_class {{#if foobar}}{{my_helper foobar}}{{/if}}"></div>
{{/each}}

这是因为甲型异构体插入文字标签持有人,而if 帮助人。 我的第二个尝试是:

{{#each content}}
    <div class="other_class {{my_helper foobar}}"></div>
{{/each}}

这是因为,如果不存在禁忌,便通过《<条码>>“foobar”,将“条码”改为“条码”。

我知道,如果做的话,{{>untre foo/code>,就会使价值失去约束力,从而没有文字标签持有人。 是否有办法以无约束的方式使用<代码>。

最佳回答

页: 1 http://jsfiddle.net/pangratz666/MvpUZ/:

App.MyView = Ember.View.extend({
    classNameBindings:  omg .w(),

    omg: function(){
        var foobar = Ember.getPath(this,  content.foobar );
        return (foobar && foobar === 42) ?  my-class-name  : null;
    }.property( content.foobar )
});
问题回答

有一个帮助者。 http://emberjs.com/api/classes/Ember.Handlebars.helpers.html#method_un contraIf”rel=“nofollow”文件

你们可以这样做:

{{#unboundIf "content.shouldDisplayTitle"}}
  {{content.title}}
{{/unboundIf}}

只是一次评估这一表述。





相关问题
Are Recursive Collections possible in sproutcore2?

I have a customizable navigation tree that can be nested 3 levels deep. Templates: <script type="text/x-handlebars" data-template-name="NavItemView"> <a {{bindAttr href="href" class="...

ember.js widgets

I know that ember js is good for single page apps and it appears that you can localize ember js app to a single dom container rather than the whole page, so I m wondering if ember js would be a good ...

Ember.js binding models stored within an array

What is the correct way to bind from one model to another when the models are stored within an array? Typically I d imagine that this would be a Controller s content array, but to keep the example ...

rendering views dynamically on EmberJS

I just having a little trouble to implement a special kind of view for Ember, I m digging on the source for days but can t find how to make it work... Can you take a look and tell me what s wrong? It ...