Skip to content

项目链接概念#

¥Item linking concepts

节点创建的每个输出项都包含元数据,这些元数据将其链接到节点用于生成它们的输入项(或多个输入项)。此教程将创建一个项目链,你可以沿着该链回溯访问之前的项目。这可能比较复杂,尤其是在节点拆分或合并数据的情况下。在构建你自己的程序化节点时,或者在某些情况下使用代码节点时,你需要了解项目链接。

¥Each output item created by a node includes metadata that links them to the input item (or items) that the node used to generate them. This creates a chain of items that you can work back along to access previous items. This can be complicated to understand, especially if the node splits or merges data. You need to understand item linking when building your own programmatic nodes, or in some scenarios using the Code node.

本文档提供了此功能的概念性概述。有关使用详情,请参阅:

¥This document provides a conceptual overview of this feature. For usage details, refer to:

¥Item linking for node creators, for details on how to handle item linking when building a node.

¥Item linking in the Code node, to learn how to handle item linking in the Code node.

¥Item linking errors, to understand the errors you may encounter in the editor UI.

n8n 的自动项目链接#

¥n8n's automatic item linking

如果节点无法控制如何将输入项链接到输出项,n8n 会尝试自动猜测如何链接这些项:

¥If a node doesn't control how to link input items to output items, n8n tries to guess how to link the items automatically:

  • 单输入单输出:输出链接到输入。

¥Single input, single output: the output links to the input.

  • 单输入多输出:所有输出都链接到该输入。

¥Single input, multiple outputs: all outputs link to that input.

  • 多个输入和输出

¥Multiple inputs and outputs:

  • 如果你保留输入项,但更改顺序(或删除一些项但保留其他项),n8n 可以自动添加正确的链接项信息。

    ¥If you keep the input items, but change the order (or remove some but keep others), n8n can automatically add the correct linked item information.

  • 如果输入和输出的数量相等,n8n 会按顺序链接这些项目。这意味着输出 1 链接到输入 1,输出 2 链接到输入 2,依此类推。

    ¥If the number of inputs and outputs is equal, n8n links the items in order. This means that output-1 links to input-1, output-2 to input-2, and so on.

  • 如果数字不相等,或者你创建了全新的项,n8n 将无法自动链接项。

    ¥If the number isn't equal, or you create completely new items, n8n can't automatically link items.

如果 n8n 无法自动链接项目,且节点不处理项目链接,则 n8n 会显示错误。有关更多信息,请参阅 项目链接错误

¥If n8n can't link items automatically, and the node doesn't handle the item linking, n8n displays an error. Refer to Item linking errors for more information.

项目链接示例#

¥Item linking example

A diagram showing the threads linking multiple items back through a workflow

本示例中,即使项目顺序发生变化,n8n 也可以将一个节点中的项目链接回多个步骤。这意味着按字母顺序对电影进行排序的节点可以访问获取著名电影演员的节点中链接项的信息。

¥In this example, it's possible for n8n to link an item in one node back several steps, despite the item order changing. This means the node that sorts movies alphabetically can access information about the linked item in the node that gets famous movie actors.

访问链接项的方法取决于你使用的是 UI、表达式还是代码节点。探索以下资源:

¥The methods for accessing linked items are different depending on whether you're using the UI, expressions, or the code node. Explore the following resources:

¥Mapping in the UI

¥Mapping in the expressions editor

¥Item linking in the Code node

¥Item linking errors