在Meteor的Spacebars中使用逻辑运算符

use*_*602 3 handlebars.js meteor spacebars

是否可以在Spacebars中使用逻辑运算符(没有模板助手)?

例如:

{{#if status == '0'}}
      Hello world.
{{/if}}
Run Code Online (Sandbox Code Playgroud)

不幸的是,我收到以下错误:

   While processing files with templating (for target web.browser):
   client/views/test.html:46: Expected identifier, number, string, boolean, null, or a sub expression enclosed in "(", ")"
   ...       {{#if status == '0'}}             ...
   ^

=> Your application has errors. Waiting for file change.
Run Code Online (Sandbox Code Playgroud)

Akh*_*har 6

Spacebars无法进行比较,但您可以使用原生下划线.在客户注册它:

Template.registerHelper('_', function(){
  return _;
});
Run Code Online (Sandbox Code Playgroud)

然后像这样使用它:

{{_.isEqual status 0}}
Run Code Online (Sandbox Code Playgroud)

true如果状态为0或false其他,则返回.