【发布时间】:2016-02-01 12:39:14
【问题描述】:
在车把中,我需要检查一个对象是否为空,如果不是,则我需要运行一个循环来从对象中获取内容。下面是我的代码和codepen的链接。我想这很简单,但似乎没有任何效果。我原以为把手 #if 语句会将空对象视为未定义或 0,最终条件将无法满足。
<div class="temp"></div>
<script id="temp" type="x-handlebars-template">
{{#if tabs}}
<p>true</p>
{{/if}}
</script>
var template = Handlebars.compile($("#temp").html());
var tabs = {};
var context = {
tabs: tabs
}
$('.temp').html(template(context));
【问题讨论】:
标签: javascript loops if-statement handlebars.js