我试图将一个AJAX响应解析为一个把手模板,并不太确定如何让它工作。以下是我得到的回复:
{"results":[{"location":"Northwest","sort":0,"rep":[{"name":"Bill Murray","title":"Owner","area":"Seattle, WA","phone":"(555) 555-5555","email":"billmurray@me.com","warehouse":{"manager":"Bill Davidson","address":"555 Loring Way","city":"Seattle","state":"WA","postal_code":"55555","phone":"(555) 555-5555"}}]}]}
这是我到目前为止所尝试的内容:
{{#each location}}
{{ rep.name }}
{{ rep.title }}
{{ rep.area }}
{{/each}}
对不起,这个AJAX的东西还是很新的!
答案 0 :(得分:3)
您没有名为' location'的数组,而是您的顶级数组被称为'结果',因此您的第一个#each通话需要通过'结果& #39 ;. '代表'不是对象文字,而是数组,所以它也必须使用#each调用进行迭代:
{{#each results}}
{{#each rep}}
{{ name }}
{{ title }}
{{ area }}
{{/each}}
{{/each}}