简体   繁体   English

车把js如果条件

[英]Handlebars js if condition

My json part: 我的json部分:

var context = {
  author: [{
  id: 47,
  name: "Yehuda Katz"
},
{
  id: 48,
  name: "Kate"
},

{ id: 49, name: "Jim" } {id:49,名称:“ Jim”}

]} ]}

Handlebars 把手

{{if author}}
 <li>{{id}}</li>
 <li>{{name}}</li>
{{/if}}

I want to display the contents once author key is present. 出现作者密钥后,我想显示内容。 If not,it won't display. 如果没有,它将不会显示。

However,my above code doen't displays the author eventhough it is present. 但是,我的上述代码即使存在也没有显示作者。

Whats wrong in my code?? 我的代码有什么问题??

Handlebars block helpers (like if) need a hash character before the block statment 把手挡块助手(例如if)需要在挡块语句前使用哈希字符

so instead of 所以代替

{{if author}}
 <li>{{id}}</li>
 <li>{{name}}</li>
{{/if}}

do

{{#if author}}
 <li>{{id}}</li>
 <li>{{name}}</li>
{{/if}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM