假手柄时,手柄不呈现布尔变量 [英] Handlebars doesn't render boolean variables when false

查看:71
本文介绍了假手柄时,手柄不呈现布尔变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Handlebars.js有一些奇怪的行为。它呈现一个值为true的布尔值作为字符串true,但是其值为。

  var booleanTestTrue = true; 
var booleanTestFalse = false;

模板:

  True:{{booleanTestTrue}} 
False:{{booleanTestFalse}}

渲染到:

  True:true 
False:(空字符串)

有什么办法可以解决这个问题吗?或者我必须编写一个帮助程序?

解决方案

您可以使用简单的块帮助程序,并执行#if,如下所示: / p>

  {{#if isTrue}} 
true
{{else}}
false
{{/ if}}


Handlebars.js has some weird behavior. It renders a boolean with a value of true as the string "true", but a value of false as "".

var booleanTestTrue = true;
var booleanTestFalse = false;

Template:

True: {{booleanTestTrue}}
False: {{booleanTestFalse}}

Renders to:

True: true
False: (empty string)

Is there any way to fix this problem? Or do I have to write a helper?

解决方案

You can use a simple block helper and implement #if like the following:

{{#if isTrue}}
       true
{{else}}
       false
{{/if}}

这篇关于假手柄时,手柄不呈现布尔变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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