0

我正在尝试在 SendWithUs 中使用jinja. 我的数据包含一个双嵌套变量。

> {   "bookingList": [
>     {
>       "attendees": [
>         {
>           "age": "8",
>           "name": "Tommy"
>         },
>         {
>           "age": "9",
>           "name": "Mila"
>         }
>       ],
>       "classStartTime": "2020-01-30T17:00:00.000Z",
>       "classTitle": "Test class",
>       "count": "2",
>       "price": "10"
>     },
>     {
>       "attendees": [
>         {
>           "age": "8",
>           "name": "Tommy"
>         },
>         {
>           "age": "9",
>           "name": "Mila"
>         }
>       ],
>       "classStartTime": "2020-01-30T17:00:00.000Z",
>       "classTitle": "Test class 2",
>       "count": "2",
>       "price": "10"
>     }   ],   "customerInfo": {
>     "email": "test@test.com",
>     "firstName": "test"   },   "orderInfo": {
>     "orderId": "64d02680-364d-11ea-981c-42010a2ad1c1",
>     "subtotalPaid": "32.09",
>     "taxPaid": "3.94",
>     "totalPaid": "36.03"   },   "subject": "Test 123" }

我正在尝试获取数据以显示

这些是您的注册详细信息:
{{bookingList.attendees.name}}注册{{bookingList.classTitle}}{{bookingList.classStartTime}}

它正确地显示了classTitleclassStartTime,但是用这个词'name'代替了实际的名字。

你如何处理双重嵌套变量?

4

1 回答 1

0

基本上你想要做的是在 for 循环中有一个 for 循环。这是我认为您正在尝试做的简化示例:

<html>
  <head></head>
  <body>
    These are your enrollment details: <br>
    {% for item in bookingList %}
      {% for attendee in item.attendees  %}
      {{attendee.name}} is enrolled in {{item.classTitle}} on {{item.classStartTime}} <br>
      {% endfor %}
    {% endfor %}
  </body>
</html>

呈现为:

These are your enrollment details:
Tommy is enrolled in Test class on 2020-01-30T17:00:00.000Z
Mila is enrolled in Test class on 2020-01-30T17:00:00.000Z
Tommy is enrolled in Test class 2 on 2020-01-30T17:00:00.000Z
Mila is enrolled in Test class 2 on 2020-01-30T17:00:00.000Z
于 2020-01-24T19:37:00.517 回答