Blaze:{{#if}}语句中的逻辑(非,或,与...) [英] Blaze: Logic (Not, Or, And…) in {{#if}} statement

查看:407
本文介绍了Blaze:{{#if}}语句中的逻辑(非,或,与...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以在{{#if}}语句中进行逻辑运算? 我希望有这样的东西:

Is there a way to do logic operation in {{#if}} statement? I was hoping for something like:

{{#if A && B}}
  some html
{{/if}}

我找不到关于大量逻辑的文档,所以我猜它不受支持.我只是想确定一下.很抱歉这个愚蠢的问题...

I couldn’t find documentation about logic in blaze, so I guess it’s not supported. I just wanted to be sure. Sorry for the rather stupid question...

推荐答案

如Billy Bob所建议的那样,您将需要参数化的助手.您可以在任何情况下使用以下两个全局帮助器:

As Billy Bob suggests, you would need parameterized helpers. Here are two global helpers you could use in any context:

Template.registerHelper('and',(a,b)=>{
  return a && b;
});
Template.registerHelper('or',(a,b)=>{
  return a || b;
});

然后您可以将它们用于:

Then you could use these with:

{{#if and a b}}
  a and b are both true-ish
{{/if}}
{{#if or a b}}
  a or b is true-ish
{{/if}}

这篇关于Blaze:{{#if}}语句中的逻辑(非,或,与...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆