跳至内容

项目链接#

仅限编程风格节点

本指南适用于编程式节点。如果您使用的是声明式风格,n8n会自动为您处理配对项。

利用n8n的项链接功能访问当前项之前项的数据。n8n需要知道给定输出项来自哪个输入项。如果缺少此信息,其他节点中的表达式可能会中断。作为节点开发者,您必须确保节点返回的任何项都支持此功能。

这适用于编程式节点(包括触发器节点)。构建声明式节点时无需考虑项目链接。更多关于节点样式的信息,请参阅选择您的节点构建方式

首先阅读项目链接概念,该文档提供了项目链接的概念性概述,并详细介绍了n8n可以自动处理链接的场景。

如果需要手动处理项目链接,可以通过在节点返回的每个项目上设置pairedItem来实现:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
// Use the pairedItem information of the incoming item
newItem = {
	"json": { . . . },
	"pairedItem": {
		"item": item.pairedItem,
		// Optional: choose the input to use
		// Set this if your node combines multiple inputs
		"input": 0
};

// Or set the index manually
newItem = {
		"json": { . . . }
		"pairedItem": {
			"item": i,
			// Optional: choose the input to use
			// Set this if your node combines multiple inputs
			"input": 0
		},
};
优云智算