我试图在另一个迭代器中使用迭代助手。但内部帮助者没有输出任何东西。
这是车把模板:
{{#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/
发布于 2015-09-12 15:07:02
{{#people}}.{{/people}}一词产生了三个上下文:
{ firstName: "Yehuda", lastName: "Katz" },
{ firstName: "Carl", lastName: "Lerche" },
{ firstName: "Alan", lastName: "Johnson" }因此,在这些上下文中没有学生,这就是为什么内部表达式{{#students}}.{{/students}}没有输出的原因。
你能详细说明一下你想要达到的目标吗?
发布于 2015-09-14 06:19:33
非常感谢J P....your的回答很棒.正确的代码是:
{
people : [
{ firstName: "Yehuda", lastName: "Katz", students: [{ firstName1: "Mike", lastName1: "Smith"
}] },
{ firstName: "Carl", lastName: "Lerche", students: [{ firstName1: "Mike", lastName1: "Smith"
}] },
{ firstName: "Alan", lastName: "Johnson", students: [{ firstName1: "Mike", lastName1: "Smith"
}] }
],
}https://stackoverflow.com/questions/32539626
复制相似问题