Skip to content

在表达式编辑器中进行映射#

¥Mapping in the expressions editor

以下示例展示了如何在表达式编辑器中访问链接项。有关表达式(包括内置变量和方法)的更多信息,请参阅 expressions

¥These examples show how to access linked items in the expressions editor. Refer to expressions for more information on expressions, including built in variables and methods.

有关映射和链接项时出现的错误信息,请参阅 项目链接错误

¥For information on errors with mapping and linking items, refer to Item linking errors.

访问上一个节点输出中的链接项#

¥Access the linked item in a previous node's output

使用此作用域时,n8n 会沿着项目链接链向上查找给定节点中的父项。

¥When you use this, n8n works back up the item linking chain, to find the parent item in the given node.

1
2
// Returns the linked item
{{$("<node-name>").item}}

举个更详细的例子,假设工作流中较早的节点具有以下输出数据:

¥As a longer example, consider a scenario where a node earlier in the workflow has the following output data:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
[
  {
    "id": "23423532",
    "name": "Jay Gatsby",
  },
  {
    "id": "23423533",
    "name": "José Arcadio Buendía",
  },
  {
    "id": "23423534",
    "name": "Max Sendak",
  },
  {
    "id": "23423535",
    "name": "Zaphod Beeblebrox",
  },
  {
    "id": "23423536",
    "name": "Edmund Pevensie",
  }
]

要提取名称,请使用以下表达式:

¥To extract the name, use the following expression:

{{$("").item.json.name}}

访问当前节点输入中的链接项#

¥Access the linked item in the current node's input

在这种情况下,项目链接位于节点内部:查找节点链接到输出项的输入项。

¥In this case, the item linking is within the node: find the input item that the node links to an output item.

1
2
// Returns the linked item
{{$input.item}}

举个更详细的例子,假设当前节点具有以下输入数据:

¥As a longer example, consider a scenario where the current node has the following input data:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
[
  {
    "id": "23423532",
    "name": "Jay Gatsby",
  },
  {
    "id": "23423533",
    "name": "José Arcadio Buendía",
  },
  {
    "id": "23423534",
    "name": "Max Sendak",
  },
  {
    "id": "23423535",
    "name": "Zaphod Beeblebrox",
  },
  {
    "id": "23423536",
    "name": "Edmund Pevensie",
  }
]

通常情况下,你可以使用拖放 数据映射 节点来提取名称,但你也可以编写以下表达式:

¥To extract the name, you'd normally use drag-and-drop Data mapping, but you could also write the following expression:

{{$input.item.json.name}}