简体   繁体   English

如何处理简单的、不复杂的值列表?

[英]How do I work with a list of simple, not-complex, values?

When looking at the docs for Lists ( https://opensource.adobe.com/pdftools-sdk-docs/docgen/latest/templatetags.html#lists ), it demonstrates an array of objects:在查看列表文档( https://opensource.adobe.com/pdftools-sdk-docs/docgen/latest/templatetags.html#lists )时,它演示了一个对象数组:

{
  "products": [
    {
      "productName": "Adobe Photoshop"
    },
    {
      "productName": "Adobe Premiere Pro"
    },
    {
      "productName": "Adobe InDesign"
    }
}

And in the Word doc, it uses:在 Word 文档中,它使用:

{% repeating-section products %}
{{ productName }}
{% end-section %}

While this works, typically an array of names would not be objects, but just names:虽然这有效,但通常名称数组不会是对象,而只是名称:

{
 "products": [ "foo", "moo", "goo"]
}

How would I iterate over this in my Word document?我将如何在我的 Word 文档中对此进行迭代?

As you pointed out, the docs assume an array of objects, not simple values, which is why when you are inside the repeating section, you can reference the key and the implication is that it will point to the current array item as it loops.正如您所指出的,文档假定一个对象数组,而不是简单的值,这就是为什么当您在重复部分中时,您可以引用键,这意味着它将在循环时指向当前数组项。

I took a look at the JSONata docs related to arrays ( http://docs.jsonata.org/simple ) and noticed the use of $[0] .我查看了与 arrays ( http://docs.jsonata.org/simple ) 相关的 JSONata 文档,并注意到$[0]的使用。 The docs mentioned that $ refers to the entire input document.文档提到 $ 指的是整个输入文档。 On a whim, I tried that in my Word doc:一时兴起,我在我的 Word 文档中进行了尝试:

{% repeating-section products %}
{{ $[0] }}
{% end-section %}

And of course changed my data to be simple values - and this worked.当然,将我的数据更改为简单的值 - 这很有效。 My guess is that inside the loop, the $[0] refers to the current array item.我的猜测是在循环内部, $[0] 指的是当前数组项。 I also tested {{ $[0].name }} in my Word doc where name was a simple value, and it worked the same as {{ name }} , so it feels like this is a safe answer/suggestion.我还在我的 Word 文档中测试{{ $[0].name }} ,其中name是一个简单的值,它的工作方式与{{ name }}相同,所以感觉这是一个安全的答案/建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM