《n8n Item Lists 节点:数组操作全攻略(排序、过滤、分组、去重、合并)》

🚀 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 节点的数量。

相关推荐
测试开发技术1 天前
Agent自动化工作流:n8n、dify、coze,谁更强?
ai·自动化·agent·dify·智能体·coze·n8n
2022.11.7始学前端2 天前
n8n第四节 表单触发器:让问卷提交自动触发企微消息推送
java·前端·数据库·n8n
阿坡RPA2 天前
告别Docker命令:免费领取n8n一键部署安装包
n8n
2022.11.7始学前端5 天前
n8n第二节 实现小卖部商品财务报表自动化生成
java·n8n
陈奕昆5 天前
n8n实战营Day1课时2:核心概念拆解+天气提醒工作流实操
开发语言·人工智能·n8n
陈奕昆5 天前
n8n实战营Day2:复杂逻辑控制·HTTP请求+条件分支节点实操
网络·人工智能·python·网络协议·n8n
公众号-架构师汤师爷5 天前
n8n工作流实战:让DeepSeek一键拆解100篇公众号爆文,扒得底裤都不剩(建议收藏)
人工智能·智能体·n8n
陈奕昆6 天前
n8n实战营Day3:电商订单全流程自动化·需求分析与流程拆解
大数据·开发语言·人工智能·自动化·需求分析·n8n
陈奕昆6 天前
n8n实战营Day1课时3:高频节点解析+Webhook表单同步Excel实操
人工智能·python·n8n