Handlebars 模板不显示数据
Handlebars Template Doesn't Display Data
我的 Handlebars 模板:
{{#each .}}
{{this}}
{{title}}<br>
{{author}}
{{/each}}
部分数据示例:
[
{
title:"How We Solve Big Problems By Thinking Small",
link:"http://product.hubspot.com/blog/how-our-product-team-thinks-small-to-solve-big-problems",
published:"2015-03-05T13:30:00.000Z",
author:"jboulter@hubspot.com (Jeff Boulter)",
site:"http://product.hubspot.com/blog"
},
{
title:"4 steps to better goals and metrics",
link:"http://engineering.pinterest.com/post/112720487359",
published:"2015-03-04T20:56:27.000Z",
author:"",
site:"http://engineering.pinterest.com/"
},
{
title:"33 Browser Stats You Just Might Believe",
link:"http://code.flickr.net/2015/03/04/browsers-in-2014/",
published:"2015-03-04T17:47:15.000Z",
author:"Phil Dokas",
site:"http://code.flickr.net"
}
]
似乎 {{this}} 打印出了整个 blob,这是我能正确显示的范围。
查看 github 上的项目以获得完整的上下文,this commit :)
非常感谢任何帮助。
看起来你的负载是一个字符串而不是一个解析的 JSON 数组。
尝试
payload = JSON.parse(payload);
然后在您的把手模板中使用
{{#each payload}}
{{title}}<br>
{{author}}
{{/each}}
我的 Handlebars 模板:
{{#each .}}
{{this}}
{{title}}<br>
{{author}}
{{/each}}
部分数据示例:
[
{
title:"How We Solve Big Problems By Thinking Small",
link:"http://product.hubspot.com/blog/how-our-product-team-thinks-small-to-solve-big-problems",
published:"2015-03-05T13:30:00.000Z",
author:"jboulter@hubspot.com (Jeff Boulter)",
site:"http://product.hubspot.com/blog"
},
{
title:"4 steps to better goals and metrics",
link:"http://engineering.pinterest.com/post/112720487359",
published:"2015-03-04T20:56:27.000Z",
author:"",
site:"http://engineering.pinterest.com/"
},
{
title:"33 Browser Stats You Just Might Believe",
link:"http://code.flickr.net/2015/03/04/browsers-in-2014/",
published:"2015-03-04T17:47:15.000Z",
author:"Phil Dokas",
site:"http://code.flickr.net"
}
]
似乎 {{this}} 打印出了整个 blob,这是我能正确显示的范围。
查看 github 上的项目以获得完整的上下文,this commit :)
非常感谢任何帮助。
看起来你的负载是一个字符串而不是一个解析的 JSON 数组。
尝试
payload = JSON.parse(payload);
然后在您的把手模板中使用
{{#each payload}}
{{title}}<br>
{{author}}
{{/each}}