Pug模板,为多行JSON添加分隔线

时间:2018-02-23 20:51:56

标签: json pug

我有一个JSON,其中一个键具有多行值。

我正在尝试使用分隔线在多行中渲染它,但它会在一行中显示它。

https://codepen.io/anon/pen/mXjZZR

<pre>
    -
      var example = [
        {
          "company": "Orange Software",
          "website": "example.com",
          "summary": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
          "services": [
            "Customer experience",
            "Digital strategy",
            "Velocity development"
          ]
        }
      ];

  body

    for i in example
      h1 #{i.company}
      p #{i.services}

</pre>

1 个答案:

答案 0 :(得分:0)

目前services数组中的所有项都会附加到<p>段落标记中,因此它会显示在一行中。

<h1>Orange Software</h1>
<p>Customer experience,Digital strategy,Velocity development</p>

要以不同的方式显示它,您还应该迭代services数组,并将单个数组项添加到单独的<p>段元素中。

for i in example
  h1 #{i.company}
  for j in i.services
    p #{j}

呈现的目标,

<h1>Orange Software</h1>
<p>Customer experience</p>
<p>Digital strategy</p>
<p>Velocity development</p>

请告诉我这是否有帮助。