【问题标题】:Pug template, add breaklines to multiline JSONPug 模板,向多行 JSON 添加断线
【发布时间】:2018-02-23 20:51:55
【问题描述】:

我有一个带有多行值的键的 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>

【问题讨论】:

  • 您的意思是您希望服务数组项显示在多行上,对吗?如果是这样,您将不得不迭代您的服务数组。

标签: json pug


【解决方案1】:

目前services数组中的所有项目都附加到&lt;p&gt;段落标签中,因此它显示在一行中。

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

要在不同的行中显示它,您还应该迭代 services 数组,并添加单独的数组项以分隔 &lt;p&gt; 段落元素。

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>

请让我知道这是否有帮助。

【讨论】:

  • 很高兴能帮上忙。您可以选择正确的答案并对其进行投票,以便对其他用户有所帮助。谢谢。
猜你喜欢
  • 1970-01-01
  • 2020-02-14
  • 1970-01-01
  • 2020-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多