Evaluate two conditions in handlebar using ember

2019-04-27 23:10发布

I was wondering if its possible to do something like this:

{{#if ClientController.Client.number && PhoneController.hasLinesToInstall}}
...
{{/if}}}

Thanks,

Juanitos

3条回答
不美不萌又怎样
2楼-- · 2019-04-27 23:25

For me, this worked:

Ember.computed.and('firstComputedProperty', 'secondComputedProperty')
查看更多
叛逆
3楼-- · 2019-04-27 23:42

I don't think it's possible to chain conditions like that in handlebars like that - I can't find anything about it in the documentation.

You could nest them though, like this:

{{#if ClientController.Client.number}}
    {{#if PhoneController.hasLinesToInstall}}
        ...
    {{/if}}
{{/if}}

That would achieve the same outcome.

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-04-27 23:44

It's not supported out-of-the-box, but you can use the addon https://github.com/jmurphyau/ember-truth-helpers:

ember install ember-truth-helpers

Then, in your template:

{{#if (and ClientController.Client.number PhoneController.hasLinesToInstall)}}
  ...
{{/if}}}

Previously, the community's understanding was that templates should be largely free of logic. Overtime, our viewpoint has shifted towards putting more declarative logic in templates-- along with ember-truth-helpers, ember-composable-helpers is a great example of this.

查看更多
登录 后发表回答