Accessing linked items in the Code node#
节点输入数据中的每个项目都链接回在前面节点中用于生成它的项目。如果您需要从比直接前一个节点更远的地方检索链接项目,这很有用。
要访问工作流早期的链接项目,请使用 ("<node-name>").itemMatching(currentNodeinputIndex)。
例如,考虑执行以下操作的工作流:
- 客户数据存储节点生成示例数据:
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" }, ... ] - 编辑字段节点简化此数据:
1 2 3 4 5 6 7 8 9
[ { "name": "Jay Gatsby" }, { "name": "José Arcadio Buendía" }, ... ] - The Code node restores the email address to the correct person:
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 | |
1 2 3 4 | |
You can view and download the example workflow from n8n website | itemMatching usage example.