【问题标题】:Using logical operators in Meteor's Spacebars在 Meteor 的空格键中使用逻辑运算符
【发布时间】:2016-01-05 19:58:24
【问题描述】:

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

例如:

{{#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.

【问题讨论】:

标签: meteor handlebars.js spacebars


【解决方案1】:

空格键无法比较,但您可以使用本机underscore。在客户端注册它:

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

然后像这样使用它:

{{_.isEqual status 0}}

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

【讨论】:

    最近更新 更多