车把模板不显示数据

Handlebars Template Doesn't Display Data

本文关键字:显示 数据      更新时间:2023-09-26

我的车把模板:

      {{#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}}打印出整个斑点,这是我所能让它正确显示的。

请参阅github上的项目,有关完整上下文,此提交:)

任何帮助非常感谢。

看起来您的有效负载是一个字符串,而不是一个解析的 JSON 数组。

尝试

payload = JSON.parse(payload);

然后在您的车把模板中使用

{{#each payload}}
  {{title}}<br>
  {{author}}
{{/each}}