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

从工作流早期检索链接项目#

节点输入数据中的每个项目都链接回在前面节点中用于生成它的项目。如果您需要从比直接前一个节点更远的地方检索链接项目,这很有用。

要访问工作流早期的链接项目,请使用 ("<node-name>").itemMatching(currentNodeinputIndex)

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

  1. 客户数据存储节点生成示例数据:
     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": "[email protected]",
    		"notes": "Keeps asking about a green light??",
    		"country": "US",
    		"created": "1925-04-10"
    	},
    	{
    		"id": "23423533",
    		"name": "José Arcadio Buendía",
    		"email": "[email protected]",
    		"notes": "Lots of people named after him. Very confusing",
    		"country": "CO",
    		"created": "1967-05-05"
    	},
    	...
    ]
    
  2. 编辑字段节点简化此数据:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    [
    	{
    		"name": "Jay Gatsby"
    	},
    	{
    		"name": "José Arcadio Buendía"
    	},
        ...
    ]
    
  3. 代码节点将电子邮件地址恢复给正确的人:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    [
    	{
    		"name": "Jay Gatsby",
    		"restoreEmail": "[email protected]"
    	},
    	{
    		"name": "José Arcadio Buendía",
    		"restoreEmail": "[email protected]"
    	},
    	...
    ]
    

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

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();
1
2
3
4
for i,item in enumerate(_input.all()):
	_input.all()[i].json.restoreEmail = _('Customer Datastore (n8n training)').itemMatching(i).json.email

return _input.all();

您可以从 n8n 网站 | itemMatching 使用示例 查看和下载示例工作流。