🚀 n8n Item Lists 节点:数组处理最强工具(超详细教程)
Item Lists 节点是 n8n 中最重要的"数组处理工具"。
如果你经常需要:
-
过滤数据(filter)
-
排序(sort)
-
去重(unique)
-
分组(aggregate / group)
-
合并多个字段
-
把 item list 转成 map / array
那么 Item Lists 必须会用。
它是数据预处理必备节点,特别常用于:
-
CRM 数据处理
-
API 分页数据合并
-
Excel / Google Sheets 行处理
-
AI 批量任务前清洗数据
本篇一次性讲透。
📌 1. Item Lists 是干什么的?
一句话:
Item Lists = 对 nodes 输出的 items 数组进行各种操作(过滤、排序、去重、聚合、取字段等)。
它不像 Function/Code 节点写代码,而是纯 UI 配置,非常适合不会代码的人。
你只要给它输入 items,它就能通过不同模式(Operation)来 transform 数据。
📌 2. Item Lists 操作模式详解(最常用的 6 个)
在 Item Lists 中你会看到这些操作模式(Operation):
| Operation 类型 | 说明 |
|---|---|
| Filter | 过滤数据 |
| Sort | 排序 |
| Aggregate | 聚合、分组、求和 |
| Unique | 去重 |
| Limit | 截取前 N 条 |
| Split out / Combine | 拆分或合并 list |
| Pick / Remove Fields | 白名单/黑名单字段 |
下面我讲你最常用的几项。
📌 3. UI 操作详解(最常用 5 个)
✔ ① Filter(过滤)
用途:保留符合条件的数据。
例:
保留 price > 50 的商品
配置:
-
Field:
price -
Operation:
greater -
Value:
50
✔ ② Sort(排序)
例:按更新时间倒序
-
Field:
updatedAt -
Order:
DESC
✔ ③ Aggregate(聚合)
用途:做统计、按字段分组。
例:统计每个客户订单总金额
-
Group Field:customer
-
Aggregate:sum(price)
得到结构:
[
{ "customer": "A", "sum_price": 100 },
{ "customer": "B", "sum_price": 220 }
]
✔ ④ Unique(去重)
用途:根据某一字段去重。
例:按 email 去重
- Field:email
✔ ⑤ Limit(截取)
例:只取前 10 条数据
📌 4. 流程图(Item Lists 的位置)
+-----------+ +------------------+ +----------------+
| Source | ---> | Item Lists | ---> | Next Node |
+-----------+ | (过滤/排序/聚合) | +----------------+
+------------------+
📌 5. 测试数据(用于教程 + Demo)
请放入一个 Set 节点:
[
{ "customer": "A", "price": 30, "type": "food" },
{ "customer": "A", "price": 50, "type": "food" },
{ "customer": "A", "price": 20, "type": "drink" },
{ "customer": "B", "price": 100, "type": "food" },
{ "customer": "B", "price": 90, "type": "drink" }
]
📌 6. Item Lists 场景案例(非常贴近真实需求)
✔ 场景 1:过滤价格大于 50 的商品
输出:
[
{ "customer": "B", "price": 100, "type": "food" },
{ "customer": "B", "price": 90, "type": "drink" }
]
✔ 场景 2:按价格排序(从小到大)
返回:
[
{ "price": 20 },
{ "price": 30 },
...
]
✔ 场景 3:按 customer 分组求和(Aggregate)
配置
-
Group Field:customer
-
Aggregate: sum(price) → total_price
输出
[
{ "customer": "A", "total_price": 100 },
{ "customer": "B", "total_price": 190 }
]
✔ 场景 4:按 type 去重
Field:type
输出:
[
{ "type": "food" },
{ "type": "drink" }
]
📌 7. 完整可导入 Workflow(JSON)
复制以下 JSON → n8n 中 Import → 就能跑通。
🔻 DEMO:包含 Filter + Sort + Aggregate + Unique
{
"nodes": [
{
"id": "1",
"name": "Set Test Data",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [300, 300],
"parameters": {
"values": {
"json": [
{
"name": "items",
"value": "[{\"customer\":\"A\",\"price\":30,\"type\":\"food\"},{\"customer\":\"A\",\"price\":50,\"type\":\"food\"},{\"customer\":\"A\",\"price\":20,\"type\":\"drink\"},{\"customer\":\"B\",\"price\":100,\"type\":\"food\"},{\"customer\":\"B\",\"price\":90,\"type\":\"drink\"}]"
}
]
}
}
},
{
"id": "2",
"name": "Item Lists - Filter",
"type": "n8n-nodes-base.itemLists",
"typeVersion": 1,
"position": [600, 150],
"parameters": {
"operation": "filter",
"rules": {
"rules": [
{
"field": "price",
"operation": "greater",
"value": 50
}
]
}
}
},
{
"id": "3",
"name": "Item Lists - Sort",
"type": "n8n-nodes-base.itemLists",
"typeVersion": 1,
"position": [600, 300],
"parameters": {
"operation": "sort",
"sortFieldsUi": {
"sortField": [
{
"field": "price",
"order": "asc"
}
]
}
}
},
{
"id": "4",
"name": "Item Lists - Aggregate",
"type": "n8n-nodes-base.itemLists",
"typeVersion": 1,
"position": [600, 450],
"parameters": {
"operation": "aggregate",
"fieldsToAggregate": {
"fieldToAggregate": [
{
"fieldToAggregate": "price",
"operation": "sum",
"outputFieldName": "total_price"
}
]
},
"groupByFields": "customer"
}
},
{
"id": "5",
"name": "Item Lists - Unique",
"type": "n8n-nodes-base.itemLists",
"typeVersion": 1,
"position": [600, 600],
"parameters": {
"operation": "unique",
"uniqueFields": "type"
}
}
],
"connections": {
"Set Test Data": {
"main": [
[
{ "node": "Item Lists - Filter", "type": "main", "index": 0 }
],
[
{ "node": "Item Lists - Sort", "type": "main", "index": 0 }
],
[
{ "node": "Item Lists - Aggregate", "type": "main", "index": 0 }
],
[
{ "node": "Item Lists - Unique", "type": "main", "index": 0 }
]
]
}
}
}
📌 8. 最佳实践(项目中一定要知道)
⭐ 1. 尽量用 Item Lists 代替 Code Node
因为 UI 配置更清晰,可维护性更强。
⭐ 2. 聚合操作尽量写在一个 Item Lists
减少节点数量。
⭐ 3. 排序 → 过滤 → 聚合 顺序很重要
不然你会得到意外结果。
📌 9. 常见踩坑点(避免90%错误)
❌ 错误 1:忘记为 Unique 指定字段
结果:完全不去重。
❌ 错误 2:Aggregate 没指定 groupField
结果:所有数据被合成一条。
❌ 错误 3:Sort 字段不在 JSON 里
结果:节点无法排序 → items 不变。
🎉 总结
| 想做 | 用 Item Lists |
|---|---|
| 过滤 JSON 数组 | ✔ Filter |
| 排序 | ✔ Sort |
| 去重 | ✔ Unique |
| 聚合/分组 | ✔ Aggregate |
| 截取前N条 | ✔ Limit |
| 字段选择 | ✔ Pick |
Item Lists 是数据清洗几乎必用的节点,掌握后能大幅减少你写 Code 节点的数量。