").itemMatching(currentNodeinputIndex)`"> 从工作流的早期阶段检索链接项 | n8n 中文网
Skip to content

从工作流的早期阶段检索链接项#

¥Retrieve linked items from earlier in the workflow

节点输入数据中的每个项目都链接回先前节点中用于生成该项目的项目。如果你需要检索比上一个节点更早的链接项,这将非常有用。

¥Every item in a node's input data links back to the items used in previous nodes to generate it. This is useful if you need to retrieve linked items from further back than the immediate previous node.

要访问工作流中先前链接的项目,请使用 ("<node-name>").itemMatching(currentNodeinputIndex) 角色。

¥To access the linked items from earlier in the workflow, use ("<node-name>").itemMatching(currentNodeinputIndex).

例如,考虑一个执行以下操作的工作流程:

¥For example, consider a workflow that does the following:

  1. 客户数据存储节点会生成示例数据:

¥The Customer Datastore node generates example data:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
[
	{
		"id": "23423532",
		"name": "Jay Gatsby",
		"email": "gatsby@west-egg.com",
		"notes": "Keeps asking about a green light??",
		"country": "US",
		"created": "1925-04-10"
	},
	{
		"id": "23423533",
		"name": "José Arcadio Buendía",
		"email": "jab@macondo.co",
		"notes": "Lots of people named after him. Very confusing",
		"country": "CO",
		"created": "1967-05-05"
	},
	...
]
2. “编辑字段”节点简化了以下数据:

¥The Edit Fields node simplifies this data:

1
2
3
4
5
6
7
8
9
[
	{
		"name": "Jay Gatsby"
	},
	{
		"name": "José Arcadio Buendía"
	},
    ...
]
3. 代码节点会将电子邮件地址恢复给正确的人:

¥The Code node restore the email address to the correct person:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[
	{
		"name": "Jay Gatsby",
		"restoreEmail": "gatsby@west-egg.com"
	},
	{
		"name": "José Arcadio Buendía",
		"restoreEmail": "jab@macondo.co"
	},
	...
]

代码节点使用以下代码执行此操作:

¥The Code node does this using the following code:

1
2
3
4
for(let i=0; i<$input.all().length; i++) {
	$input.all()[i].json.restoreEmail = $('Customer Datastore (n8n training)').itemMatching(i).json.email;
}
return $input.all();

```python for i,item in enumerate(input.all()): _input.all()[i].json.restoreEmail = ('Customer Datastore (n8n training)').itemMatching(i).json.email

return _input.all(); ```

你可以从 n8n 网站 | itemMatchin 使用示例 查看并下载示例工作流。

¥You can view and download the example workflow from n8n website | itemMatchin usage example .