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

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

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

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

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

  1. Customer Datastore 节点生成示例数据:
     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. Edit Fields 节点简化了这个数据:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    [
    	{
    		"name": "Jay Gatsby"
    	},
    	{
    		"name": "José Arcadio Buendía"
    	},
        ...
    ]
    
  3. Code 节点将电子邮件地址恢复到正确的人:
     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]"
    	},
    	...
    ]
    

Code 节点使用以下代码实现此操作:

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 使用示例 查看和下载示例工作流。

此页面是否
💬 微信

🚀 与作者交流

关注公众号
n8n实战笔记公众号
n8n实战笔记
📚 教程 💡 案例 🔧 技巧
添加微信
添加作者微信
1对1 专业指导
⚡ 快答 🎯 定制 🚀 支持