从工作流早期节点检索关联数据项#
节点输入数据中的每个数据项都会链接回先前节点中用于生成它的数据项。当您需要获取比直接前驱节点更早的数据时,这非常有用。
要访问工作流早期节点的关联数据项,请使用 ("<节点名称>").itemMatching(currentNodeinputIndex)
方法。
例如,考虑以下工作流:
- 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": "gatsby@west-egg.com", "notes": "Keeps asking about a green light??", "country": "US", "created": "1925-04-10" }, { "id": "23423533", "name": "José Arcadio Buendía", "email": "jab@macondo.co", "notes": "Lots of people named after him. Very confusing", "country": "CO", "created": "1967-05-05" }, ... ]
- Edit Fields 节点简化这些数据:
1 2 3 4 5 6 7 8 9
[ { "name": "Jay Gatsby" }, { "name": "José Arcadio Buendía" }, ... ]
- Code 节点将电子邮件地址还原给正确的人:
1 2 3 4 5 6 7 8 9 10 11
[ { "name": "Jay Gatsby", "restoreEmail": "gatsby@west-egg.com" }, { "name": "José Arcadio Buendía", "restoreEmail": "jab@macondo.co" }, ... ]
Code 节点使用以下代码实现这一功能:
1 2 3 4 |
|
1 2 3 4 |
|
您可以从 n8n 官网 | itemMatchin 使用示例 查看并下载此示例工作流。