如何使用hbs文件以PDF格式呈现正确格式的数据。

时间:2017-12-19 14:53:36

标签: angularjs node.js handlebars.js

我有一个名为attribute的对象数组,我需要在hbs文件中绑定它。我成功传递了这个对象,因为我可以在hbs文件中看到数据。但它不是格式化视图。那么如何以我想要的方式呈现属性或对象。

var obj = {
  "attributes": [
    {
      "Attr 3": "MP"
    },
    {
      "Attr 3": "Gujarat"
    },
    {
      "Attr 5": "12/14/2017"
    }
  ]
}

我想在图片中显示如下图所示。

enter image description here

我怎样才能做到这一点。

1 个答案:

答案 0 :(得分:1)

这很简单。您必须遍历对象obj,然后遍历名为attributes的数组。

{{#each obj}} 
  {{#if this.attributes}}
  Attributes:
      |
  {{#each this.attributes as |value key|}}
    {{#if value}}
      {{#each value as |val key|}}
        {{key}}: {{val}}
      {{/each}}
      |
    {{/if}}
  {{/each}}
  <br/>
  {{/if}}
{{/each}}

{{#each}}{{/each}} =&gt;这是一个迭代数组或对象的每个元素的循环。

{{#if}}{{/if}} =&gt;这是一个条件。

相关问题