Evaluate two conditions in handlebar using ember

ⅰ亾dé卋堺 提交于 2019-12-07 03:37:33

问题


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

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

Thanks,

Juanitos


回答1:


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.




回答2:


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.




回答3:


For me, this worked:

Ember.computed.and('firstComputedProperty', 'secondComputedProperty')


来源:https://stackoverflow.com/questions/16589624/evaluate-two-conditions-in-handlebar-using-ember

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