问题描述:

How can you reactively add or remove a class to an element with spacebars?

Also can anyone point me in the direction of the documentation for spacebars format.

Specifically logical functions in the {{#if condition1 && condition2}} style.

Thanks

网友答案:

Spacebars currently don't provide a way to perform logical (nor other) functions for arguments.

If you need to make logical operations on your if helper arguments in several places, it is best to define your own custom helper:

UI.registerHelper('and', function(a, b) {
  return a && b;
});

{{#if and condition1 condition2}}
  ...
{{/if}
网友答案:

Currently there are no logical operations allowed in "if" statements, but you can workaround this by providing a custom helper. The easiest way to reactively modify your class would be:

<div class="{{#if isActive}}active{{/if}}"></div>

or just

<div class="{{yieldClass}}"></div>

where yieldClass is some (possibly reactive) helper in your template.

相关阅读:
Top