跳到主要内容

项目链接#

仅适用于编程式节点

本指南适用于编程式节点。若您采用声明式风格,n8n 将自动为您处理配对项目。

通过 n8n 的项目链接功能,可访问当前项目之前各项的数据。n8n 需要明确给定输出项目源自哪个输入项目。若缺少该信息,其他节点中的表达式可能会中断。作为节点开发者,您必须确保节点返回的所有项目均支持此功能。

此要求适用于编程式节点(包括触发节点)。构建声明式节点时无需考虑项目链接。有关节点风格的详细信息,请参阅选择节点构建方法

请先阅读项目链接概念,该文档提供了项目链接的概念概述,并详细说明了 n8n 可自动处理链接的场景。

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

// 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
},
};