模板
<script id='handlebar-template'>
{{#each tags}}
{{#isObject this}}
<span>Object</span>
{{else}}
<span>String</span>
{{/isObject}}
{{/each}}
</script>
脚本
<script>
Handlebars.registerHelper('isObject', function(o) {
return typeof o === "object";
});
var props = {"tags": ["Google"]}
var html = $("#handlebar-template").html();
var template = Handlebars.compile(html);
console.log(template(props));
</script>
预期产出
<span>String</span>
实际输出
false
else
块已执行,但输出返回的是false
而不是<span>String</span>
.