跳到主要内容

面向节点创建者的条目关联#

仅适用于编程式节点

本指南适用于编程式节点。若使用声明式风格,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
},
};