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

3

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

例如:

{{#if status == '0'}}
      Hello world.
{{/if}}

很不幸,我遇到了以下错误:

   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.

也许是这个?https://dev59.com/WWox5IYBdhLWcg3w95E9#16315366 - Alex K
1个回答

6

Spacebars不能进行比较,但是你可以使用本地的underscore来实现。在客户端注册它:

Template.registerHelper('_', function(){
  return _;
});

然后像这样使用它:

{{_.isEqual status 0}}

如果状态为0,则返回true,否则返回false


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接