首页 > 解决方案 > 从嵌套对象设置 nunjucks 变量

问题描述

我为冗长的控制台日志道歉,但我需要它来解决我的问题。我正在尝试将“intro”(从底部开始)的值设置为 nunjucks 变量,只是似乎无法使用正确的语法。日志如下(来自airtables API):我使用一个函数来调用作为命名对象“应用程序”返回的数据,所以我正在尝试类似的东西

{% set intro =  applications[0].fields.intro %} 

但这不起作用。提前致谢

[
      Record {
        _table: Table {
          _base: [Base],
          id: null,
          name: 'applications',
          find: [Function],
          select: [Function: bound ],
          create: [Function],
          update: [Function],
          replace: [Function],
          destroy: [Function],
          list: [Function],
          forEach: [Function]
        },
        id: 'rec7FuJxke2mL104B',
        _rawJson: {
          id: 'rec7FuJxke2mL104B',
          fields: {},
          createdTime: '2020-10-14T15:02:53.000Z'
        },
        fields: {},
        save: [Function],
        patchUpdate: [Function],
        putUpdate: [Function],
        destroy: [Function],
        fetch: [Function],
        updateFields: [Function],
        replaceFields: [Function]
      },
      Record {
        _table: Table {
          _base: [Base],
          id: null,
          name: 'applications',
          find: [Function],
          select: [Function: bound ],
          create: [Function],
          update: [Function],
          replace: [Function],
          destroy: [Function],
          list: [Function],
          forEach: [Function]
        },
        id: 'recJWqHcYUx0Q9Cih',
        _rawJson: {
          id: 'recJWqHcYUx0Q9Cih',
          fields: [Object],
          createdTime: '2020-10-13T22:37:03.000Z'
        },
        fields: {
          Post: 'https://www.yokoco.com/career/digital-designer-art-director/',
          intro: "As well as super-hero mind powers, my last role involved collaborating with Cafédirect, the UK's first 'B' corp certified coffee company, investing 50% of their profits into Producers Direct. As Big Al's head of art, alongside a copywriter, I completed typographic treatments and illustration styles for Cafédirects up and coming poster and social campaign, Hooray for poverty-free coffee!\n",
          Job: 'Digital Designer / Art Director',
          Sent: '2020-10-13',
          Status: 'In progress'
        },
        save: [Function],
        patchUpdate: [Function],
        putUpdate: [Function],
        destroy: [Function],
        fetch: [Function],
        updateFields: [Function],
        replaceFields: [Function]
      }
    ]

标签: javascriptnunjucks

解决方案


推荐阅读