我试图在另一个中使用迭代助手。但是内在的助手并没有输出任何东西。
那是把手模板:
{{#people}}
<h4>{{firstName}} {{lastName}}</h4>
{{#students}}
<h3>{{firstName}} {{lastName}}</h3>
{{/students}}
{{/people}}
那是我的JSON:
{
people : [
{ firstName: "Yehuda", lastName: "Katz" },
{ firstName: "Carl", lastName: "Lerche" },
{ firstName: "Alan", lastName: "Johnson" }
],
students: [
{ firstName: "Mike", lastName: "Smith" },
{ firstName: "Dan", lastName: "Knight" },
{ firstName: "Griffin", lastName: "Smith" }
]
}
这个问题的解决方案是什么? 在线快速尝试代码,快速点击:http://tryhandlebarsjs.com/
答案 0 :(得分:0)
表达式{{#people}}
... {{/people}}
会产生三种情况:
{ firstName: "Yehuda", lastName: "Katz" },
{ firstName: "Carl", lastName: "Lerche" },
{ firstName: "Alan", lastName: "Johnson" }
所以在任何这些情境中都没有学生,这就是为什么内部表达式{{#students}}
... {{/students}}
没有输出。
你能详细说明你想要实现的目标吗?